如何清除在MVC4浏览器后退按钮点击浏览器缓存? [英] How to clear browser cache on browser back button click in MVC4?

查看:166
本文介绍了如何清除在MVC4浏览器后退按钮点击浏览器缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know this is a popular question in stackoverflow. 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();
}

这篇关于如何清除在MVC4浏览器后退按钮点击浏览器缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆