如何在asp mvc中重新请求返回按钮页面

时间:2014-09-19 18:13:34

标签: c# asp.net .net asp.net-mvc

我正在网站上工作。因为我在LogIn用户可以看到他的主页后创建了一个LogIn系统。 但我面临一个问题。当用户退出时我删除了所有会话和cookie。并以良好的方式将过程漏掉。之后,当我在浏览器中插入用户主页url并按Enter键时。

  像这样:www.exam.com/user/home

重定向是一个很好的方式,服务器重定向我在ligin页面。

但如果我通过浏览器的后退按钮来做这件事。浏览器显示用户主页。 这就是问题所在。

我也用facebook检查这件事。和不好的工作。

请帮我解决这个问题。因为我尽力而为,但没有任何工作。

谢谢

3 个答案:

答案 0 :(得分:3)

在我看来,更好的解决方案是将属性中的缓存生命设置为函数/控制器。可以通过添加:

来完成
[HttpGet, OutputCache(NoStore = true, Duration = 1)] 

在功能或整个控制器之前。

答案 1 :(得分:1)

您必须立即将页面设置为过期。例如:

    // disabling caching for all parent pages
    protected override void OnInit( EventArgs e ) {
        base.OnInit(e);
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.AppendHeader("Cache-Control", "no-cache, no-store");
        Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-1));
    }

我在我的母版页中有这个。这告诉浏览器不要缓存页面。因为它不再被缓存,如果该人点击后退按钮,它将导致浏览器将页面请求发送到您的服务器,此时您可以将它们重定向到登录页面。

答案 2 :(得分:1)

抱歉,但我得到了答案

这是在那个地方

How to clear browser cache on browser back button click in MVC4?

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