问题
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