对所有的浏览器禁用缓存 [英] Disabling cache on all browser

查看:195
本文介绍了对所有的浏览器禁用缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.Net VB。我试图禁用缓存throught的网站,因为我的客户是有他需要清除缓存他为了使系统工作的问题。

I'm using ASP.Net VB. I'm trying to disable caching throught the website because my client is having an issue that he needs to clear his cache in order to make the system work.

我把这一堆code在我主人的页面的Page_Load。

I put this bunch of code in my master's page page_load.

Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache)
Response.Cache.SetNoStore()
Response.Cache.SetAllowResponseInBrowserHistory(True)

在这里访问我的缓存中的铬。铬://缓存/

And access my cache in chrome here. chrome://cache/

第一个问题是,这是disbaling缓存的正确方法吗?其次是,我认为把它的母版页上会有所有页面受此影响,这是一个正确的假设?最后,我怎么知道这code是工作/如果我的浏览器仍然是存储缓存,以检查code是正确的。有任何想法吗?谢谢!

The first question is, is this the right way of disbaling caching? Next is, I assumed that putting it on master page will have all pages be affected by this, is this a correct assumption? Lastly, how do I know if this code is working/if my browser is still storing cache to check if the code is right. Any ideas? Thanks!

推荐答案

事情只能与一个行code的工作

Things can work with only one line of code

 Response.CacheControl = "no-cache";

但它是从缓存中删除现有的页面很好的做法。

But it is good practice to delete the existing page from cache.

Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";

您可以检查页面在页面加载过期或不

you can check that page is expired or not on page load

     protected void Page_Load(object sender, EventArgs e)
            {

            if (Page.IsPostBack)
             {
                    if (pageIsExpired()){
                       Response.Redirect("/Some_error_page.htm");
                    }
                    else {
                       var now = Now;
                       Session("TimeStamp") = now.ToString();
                       ViewState("TimeStamp") = now.ToString();
                    }
        }
}



      private boolean pageIsExpired()
      {
         if (Session("TimeStamp") == null || ViewState("TimeStamp") == null)
            return false;

         if (Session("TimeStamp") == ViewState("TimeStamp"))
            return true;

            return false;
      }

来源:的http://www.$c$cproject.com/Articles/11225/Disabling-browser-s-back-functionality-on-sign-out

这篇关于对所有的浏览器禁用缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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