【问题标题】:Browser Back button Issue iasp.net MVC4浏览器后退按钮问题 iasp.net MVC4
【发布时间】:2013-03-14 16:25:20
【问题描述】:

我正在使用以下代码行在使用asp.net MVC4. 注销后禁用浏览器后退按钮问题

[OutputCache(NoStore = false, Duration = 0, VaryByParam = "None")] 
        public ActionResult Logout()
        {
            try
            {
                if (Session["username"] != null)
                {
                    Session.Abandon();
                    Session.Clear();
                    Session.RemoveAll();
                    Session["username"] = null;
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
                    Response.Cache.SetNoStore();
                    return RedirectToAction("Index", "AdminPanel");
                }

               return RedirectToAction("Error", "Home");
            }
            catch (Exception e)
            {
                return RedirectToAction("Error", "Home");
            }
        }

但是,这段代码有一个问题,假设我有三页第一页是登录页(Index.cshtml),第二页成功登录页(home.cshtml),第三页是关于页(about.cshtml),现在我登录然后现在我在 about.cshtml 的第三页上移动,然后我从 about.cshtml 页面注销,它会将我重定向到 home.cshtml 页面,它会将我重定向到 login.cshtml 页面。现在,如果我单击浏览器后退按钮,然后再次将我重定向到 about.cshtml 页面,但用户无法更改或添加任何内容。 所以让我知道有没有合适的代码或方法来解决这个问题。

【问题讨论】:

    标签: asp.net-mvc-4 browser-cache back-button


    【解决方案1】:

    如果你把它放在渲染 about.cshtml 的控制器方法中,它会像你描述的那样工作:

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
    Response.Cache.SetNoStore();
    

    不是很理想,但会让你走上正轨。基本上,浏览器从登录时开始缓存 about.cshtml。告诉 logout 方法不要缓存响应并没有太大作用,因为它执行的是重定向而不是渲染。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多