2

如何在我的页面上实现注销功能,以便将用户重定向到登录页面并且不允许查看上一页?

 FormsAuthentication.SignOut(); is it enough for logout.
4

3 回答 3

3
    /// <summary>
    /// Logs the user out of their forms authentication.
    /// </summary>
    public void SignOut()
    {
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }
于 2013-05-15T13:48:52.970 回答
2

您还想在 SignOut 之后删除会话状态。

FormsAuthentication.SignOut(); 

// Remove all session variables and destroy session
context.Session.RemoveAll();
context.Session.Clear();
context.Session.Abandon();
于 2013-05-15T13:47:39.933 回答
2
Page_Load (object sender, EventArgs e) {
if (!User.IsAuthenticated) {
    Response.Redirect("login.aspx");
}

此外,我会在母版页中有它。

于 2013-05-15T13:46:07.260 回答