为什么注销仅在本地有效,而在服务器上无效

本文关键字:服务器 无效 注销 为什么 有效 | 更新日期: 2023-09-27 18:37:01

我使用此代码执行注销

public ActionResult LogOff()
    {
         FormsAuthentication.SignOut();
        // Drop all the information held in the session
        Session.Clear();
        Session.Abandon();
        // clear authentication cookie
        HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
        cookie1.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Add(cookie1);
        // clear session cookie
        HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
        cookie2.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Add(cookie2);
        foreach (var cookie in Request.Cookies.AllKeys)
        {
            Request.Cookies.Remove(cookie);
        }
        return RedirectToAction("Index", "Home");
    }

它在本地工作正常,但是当我在服务器中发布我的应用程序时,即使用户已经注销,如果用户单击浏览器的Back按钮,页面仍然会显示。

为什么注销仅在本地有效,而在服务器上无效

我希望你只是看到页面的缓存版本。

如果您按 CTRL+F5,它会要求您再次登录吗?

如果您真的想禁用此功能,请参阅MiBu给出的此答案,以防止缓存安全页面。