Disabling cache on all browser

a 夏天 提交于 2019-12-11 09:08:48

问题


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.

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/

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!


回答1:


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;
      }

Source :http://www.codeproject.com/Articles/11225/Disabling-browser-s-back-functionality-on-sign-out



来源:https://stackoverflow.com/questions/18183282/disabling-cache-on-all-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!