Reputation: 6489
I've a logged in user in my MVC web application, but IsAuthenticated
property in my Hub
class is still false. Here is my log in and redirection sequences:
Login
form.FormsAuthenticationTicket
and encrypts ticket using FormsAuthentication
class.FormsAuthentication.FormsCookieName
path.OnConnected
method, I find that it is still false.How should I handle this issue, I don't have any problem with authorization in SignalR 1.1, I'm using same code but this time with SignalR 2.0.
Update: Actually it's not still false in SignalR Hub class it's false in all over application domain.
Any advice will be helpful. Thanks in advance.
Upvotes: 0
Views: 1004
Reputation: 6489
In Visual Studio 2013, default MVC template uses ASP.Net Identity authentication system and puts <authentication mode="None" />
in web.config, so this prevents application to creates HttpCookie
. I just change it to <authentication mode="Forms" />
and now it's working.
Upvotes: 0
Reputation: 797
If you add cookie into response by yourself, you need to resolve it by yourself as well.
if(Login(model.UserName, model.Password)){
// ecrypt user data and add to cookie
// your code
}
// Global file code
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
// decrypt cookie and set current principal
// your code
Thread.CurrentPrincipal = HttpContext.Current.User = principal;
}
In additional, you need a customer principal class to store user info if traditional GenericPrincipal does not fit.
Upvotes: 2