如何在我的页面上实现注销功能,以便将用户重定向到登录页面并且不允许查看上一页?
FormsAuthentication.SignOut(); is it enough for logout.
/// <summary>
/// Logs the user out of their forms authentication.
/// </summary>
public void SignOut()
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}
您还想在 SignOut 之后删除会话状态。
FormsAuthentication.SignOut();
// Remove all session variables and destroy session
context.Session.RemoveAll();
context.Session.Clear();
context.Session.Abandon();
Page_Load (object sender, EventArgs e) {
if (!User.IsAuthenticated) {
Response.Redirect("login.aspx");
}
此外,我会在母版页中有它。