I am trying to create and Sign-In a User using Asp.Net Identity within a SignalR Hub like so:
public string CreateUser(string username, string password)
{
var userStore = new UserStore<IdentityUser>();
var manager = new UserManager<IdentityUser>(userStore);
var user = new IdentityUser() { UserName = username };
IdentityResult result = manager.Create(user, password);
if (result.Succeeded)
{
var authenticationManager = Context.Request.GetHttpContext().GetOwinContext().Authentication;
var userIdentity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { }, userIdentity);
return "Success";
}
else
{
var authenticationManager = Context.Request.GetHttpContext().GetOwinContext().Authentication;
return "Failed: "+result.Errors;
}
}
But GetHttpContext() is always null, could someone kindly explain why?
What is the best way to call the SignIn method from within a Hub?