protected void LogIn(object sender, EventArgs e) { if (IsValid) { // Validate the user password var manager = new UserManager(); ApplicationUser user = manager.Find(UserName.Text, Password.Text); if (user != null) { Session["userId"] = user.Id; ApplicationDbContext context = new ApplicationDbContext(); var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); IdentityHelper.SignIn(manager, user, RememberMe.Checked); if (UserExtension.IsInRole(user.Id, "Administrator")) { Response.Redirect("~/Admin/AdminHome.aspx"); } else if (UserExtension.IsInRole(user.Id, "Customer")) { Response.Redirect("~/User/UserHome.aspx"); } } else { FailureText.Text = "Invalid username or password."; ErrorMessage.Visible = true; } } }