Friday, 21 February 2014

how to clear cache for browser using C# .NET

Create a class:
public static class MyCache
{
 public static void ClearCache()
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now);
HttpContext.Current.Response.Cache.SetNoServerCaching();
HttpContext.Current.Response.Cache.SetNoStore();
}
}
And on page load use this :
protected void Page_Load(object sender, EventArgs e)
{
MyCache.ClearCache();
}