Delete chrome cache programatically

Viewed 459

I am trying to delete Chrome browser cache on logout of an application. I am using below set of code inside logout button click event and it doesn't clear browser cache.

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();

I also have placed the below meta tags in cshtml page and didn't help. Really appreciate any suggestions.

<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
1 Answers

You can also add with yours this lines and check it again.

HttpContext.Response.ExpiresAbsolute = DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0, 0));
HttpContext.Response.Expires = 0;
HttpContext.Response.Cache.AppendCacheExtension("no-store, no-cache, must-revalidate, proxy-revalidate, post-check=0, pre-check=0");

I also suggest to increase DateTime.UtcNow.AddDays(-1) from -1 day to -1 year at least.

Related