0

我有注销操作,可以注销并重定向到登录页面,但是当我关闭浏览器而不注销并在注销时再次打开时,它会直接重定向到登录操作而不访问注销操作

    [OutputCache(NoStore=true, Duration=0)]
    public ActionResult LogOut()
    {
        FormsAuthentication.SignOut();
        Session.Abandon();
        HttpContext.User = null;

        HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
        cookie1.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Add(cookie1);


        HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
        cookie2.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Add(cookie2);

        HttpCookie cookie3 = new HttpCookie("myCookie");
        cookie3.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Add(cookie3);

        FormsAuthentication.RedirectToLoginPage();
        return null;
    }

这是我的 webconfig 设置

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/LoginPage" 
           defaultUrl="~/User/MyKids" 
           timeout="99999999" 
           slidingExpiration="true" /> 
</authentication>
4

2 回答 2

0

我不确定您所说的“再次打开”是什么意思,但是如果您尝试访问需要“登录”用户的系统部分,那么系统会检测到您没有有效身份验证的事实,并且它正在将您重定向到配置中指定的登录页面。它不会尝试让您退出,只是尝试让您登录。这是这种情况下的正常行为。

于 2014-03-14T14:37:37.733 回答
0

这是默认行为。我猜您将表单身份验证与会话 cookie 一起使用。因此,当您再次打开浏览器并访问注销页面时,forms-authentication-module 会检测到没有可用的有效 cookie 并将您重定向到登录页面。

将 createPersistentCookie 设置为 true,以记住用户:http: //msdn.microsoft.com/en-us/library/twk5762b%28v=vs.110%29.aspx

于 2014-03-14T14:41:54.460 回答