我有一个问题:当我登录User.Identity.GetUserId()时返回正确的ID值,但是当我单击logout然后再次使用其他用户登录时User.Identity.GetUserId()返回null:
我的代码:
protected void LogIn(object sender, EventArgs e)
{
string url="";
if (IsValid)
{
// Convalidare la password utente
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();
var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);
FormsAuthentication.RedirectFromLoginPage(User.Identity.GetUserId(), false);
var roles = manager.GetRoles(User.Identity.GetUserId().ToString());
Session["Role"] = roles[0];
switch (Convert.ToString(Session["Role"]))
{
case "GruppoAzienda":
url = "G_Aziende/g_aziende.aspx";break;
case "Azienda":
url = "Aziende/Dipendenti.aspx"; break;
}
switch (result)
{
case SignInStatus.Success:
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response, url);
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 = "Tentativo di accesso non valido";
ErrorMessage.Visible = true;
break;
}
}
}
这是注销码:
protected void Unnamed_LoggingOut(object sender, LoginCancelEventArgs e)
{
Context.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
Session.Abandon();
}
有人可以帮忙吗?