Tuesday, May 25, 2010

Disabling Browser Cache In C# and ASP.NET

Disable browser caching seems to revolve around how to make it work in IE, Mozilla and other browsers.

Here is the code that will disable browser cache. I have used this and it worked for me.

//Used for disabling page caching 
 HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
 HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
 HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
// Requires for IE
 HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
// Requires for Mozilla
 HttpContext.Current.Response.Cache.SetNoStore();

No comments:

Post a Comment