如何清除在MVC4浏览器后退按钮点击浏览器缓存?

如何清除在MVC4浏览器后退按钮点击浏览器缓存?

问题描述:

我知道这是一个计算器流行的问题。我已经通过每一个同样的问题消失了,我无法找到正确的答案对我来说。
这是我注销控制器操作结果

I know this is a popular question in *. I have gone through every same question and I am unable to find the right answer for me. This is my log out controller Action Result

    [Authorize]       
    public ActionResult LogOut(User filterContext)
    {
        Session.Clear();
        Session.Abandon();
        Session.RemoveAll();
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
        Response.Cache.SetNoStore();
        FormsAuthentication.SignOut();
        return RedirectToAction("Home", true);

    }

它没有为我工作。
我也尝试加入?

It didn't work for me. I also tried adding-

< META HTTP-EQUIV =缓存控制内容=无缓存/>
< META HTTP-EQUIV =语用内容=无缓存/>
< META HTTP-EQUIV =过期的内容=0/>

没有这些解决了我的问题。

none of these resolved my issue.

与方法的问题是,你将它设置它在哪里都为时已晚MVC应用它。下面三行您code,应摆在那,你不想显示,显示视图(啥都页)的方式。

The problem with your approach is that you are setting it where it is already too late for MVC to apply it. The following three lines of your code should be put in the method that shows the view (consequently the page) that you do not want to show.

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

如果你想申请的行为关于浏览器后退没有缓存的所有页面,那么你应该把它放在Global.asax中。

If you want to apply the "no cache on browser back" behavior on all pages then you should put it in global.asax.

protected void Application_BeginRequest()
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
    Response.Cache.SetNoStore();
}