【问题标题】:Back button Issue after Logout注销后返回按钮问题
【发布时间】:2014-10-22 02:07:23
【问题描述】:

我浏览了一些链接并花费了数小时,但在单击返回按钮注销后我的页面仍然加载。这是我尝试过的注销页面代码。

protected void Page_Load(object sender, EventArgs e)
    {
    if(Session[Constants.KeyValues.UserProfileSession]== null)
     {
            Response.Redirect("www.google.com", true);
     }          

        ////Clear cookie and redirect user to login page (Landing page before login).
        Response.AddHeader("pragma", "no-cache");
        Response.AddHeader("cache-control", "private");
        Response.CacheControl = "no-cache";
        Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
        FormsAuthentication.SignOut();
        Response.Cookies.Clear();

        HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));

        HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
        HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoStore();


        Session.Clear();
        Session.Abandon();
        Session[Constants.KeyValues.UserProfileSession] = null;            
        Response.Write("<script type=\"text/javascript\">window.location.replace('www.google.com');</script>");
        //Response.Redirect("www.google.com", true);
    }

这是我的html页面

<!doctype html>
<html lang="ko">
<head>
    <title></title>
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <script type="text/javascript">
        function ClearHistory() {
            var backlen = history.length;
            history.go(-backlen);
            window.location.href = www.google.com
        }
    </script>
</head>
<body onload="ClearHistory();">
</body>
</html>

这是会员登录后页面加载的代码

protected void Page_Load(object sender, EventArgs e)
    {
    if(Session[Constants.KeyValues.UserProfileSession]== null)
     {
            Response.Redirect(SPContext.Current.Site.Url + "/_layouts/ABC/ShoppingLandingBeforeLogin.aspx", true);
     }  }

这是我尝试过的链接。

How to clear browser cache when user log off in asp.net using c#?,

How to prevent browser and proxy caching of web pages,

Browser back button issue after logout,

Clear History using javascript,

back-button-of-browser-issue-in-asp-net-logout

【问题讨论】:

  • 这不是您需要更改的注销页面的可缓存性 - 这是您要返回的页面的可缓存性。该页面上的缓存标头是什么?
  • 我不希望用户在退出后被重定向到会员页面。我无法禁用后退按钮,但可以清除浏览器的捕获。或任何其他方法来实现我的目标。
  • @Tim :我添加了当我们点击后退按钮时加载的页面代码。但是该页面来自缓存,因此无法检查会话空值。
  • @lovethakker 首次加载该页面时的缓存标头是什么?如果该页面被浏览器缓存,那么您在注销页面上设置的缓存标头无关紧要 - 它不会影响任何其他页面。
  • @Tim :我正在注销页面中的所有页面中添加元标记。但我仍然无法从缓存中删除它们。

标签: c# javascript jquery html asp.net


【解决方案1】:

尝试使用它,它适用于所有浏览器。

    Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
    Response.AppendHeader("Expires", "0"); // Proxies.

【讨论】:

  • 团队:完全没有进展。你能建议其他什么可以帮助我解决这个问题吗?
  • 我已阅读帖子back-button-issue-after-logout。我已经在我的页面中实现了它。它运作良好。唯一要记住的一点是 -> 不要通过页面加载重定向。谢谢。
猜你喜欢
  • 1970-01-01
  • 2012-05-17
  • 2020-06-04
  • 2013-07-20
  • 2023-03-29
  • 2018-06-16
  • 2019-02-06
  • 2018-08-03
  • 1970-01-01
相关资源
最近更新 更多