Reputation: 21328
Is there a way to check whether a user is logged on in a hub?.
I know I could use this, however HttpContext is not available in the hub:
HttpContext.Current.User.Identity.IsAuthenticated
-The issue is that I'm sending data to bunch of users and suppose that one of the clients is inactive for a while and his/her session expires.
What I would like to do is in my Hub => Send() method (that gets called from an event), check if the user is still logged in, if not I would send a message to his/her browser to reload a page.
Upvotes: 2
Views: 2591
Reputation: 7525
you can check using Context.User.Identity.IsAuthenticated
public class Chat : Hub
{
public void send(string message)
{
Clients.addMessage(message);
}
public void securesend(string message)
{
if (this.Context.User.Identity.IsAuthenticated)
{
// secure send.
}
}
}
Upvotes: 1
Reputation: 38764
You can use the Authorize attribute on your hub if you only want authenitcated users to be able to connect/send to the hub. If you want to get the current user then you just need to access Context.User (it's a property available on the hub).
Upvotes: 2