I have an asp.net webforms app that has a login screen. When I click the login button, the User.Identity.IsAuthenticated
is always false on the first click. Here is the code for logging in:
protected void SignIn(object sender, EventArgs e)
{
var userStore = new UserStore<ApplicationUser>();
var userManager = new UserManager<ApplicationUser>(userStore);
var user = userManager.Find(UserName.Text, Password.Text);
if (user != null && user.PasswordRetryCount < 3)
{
Session["UserName"] = user.UserName;
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
var userIdentity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties {IsPersistent = false}, userIdentity);
if (User.Identity.IsAuthenticated) //false on first click
Response.Redirect("Default.aspx");
}
}