我使用有效的Identity Framework开发Asp.Net应用程序。 它几乎可以正常工作,并且我登录得很好,但是有时我不能登录,没有错误,但是页面重定向到登录页面。
Page_Load方法的MasterPage代码在这里
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.User.Identity.IsAuthenticated && Request.Url.Segments[this.Request.Url.Segments.Length - 1].ToLower() != "login")
{
Response.Redirect("login.aspx");
}
}
我怎么了?
这是登录页代码
var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
//Son giriş Tarihi kaydet
ApplicationDbContext db = new ApplicationDbContext();
var aUser = db.Users.SingleOrDefault(x => x.Email == Email.Text);
if (aUser != null) { aUser.SonGirisTarihi = DateTime.Now; db.SaveChanges(); }
//IdentityHelper.RedirectToReturnUrl("~/", Response);
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
break;
case SignInStatus.LockedOut:
Response.Redirect("/Account/Lockout");
break;
case SignInStatus.RequiresVerification:
Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
Request.QueryString["ReturnUrl"],
RememberMe.Checked),
true);
break;
case SignInStatus.Failure:
default:
FailureText.Text = "Giriş Yapılamadı";
ErrorMessage.Visible = true;
break;
}