如何使用ASP.net(c#)清除浏览器中的所有缓存

本文关键字:浏览器 缓存 清除 ASP 何使用 net | 更新日期: 2023-09-27 18:13:48

我试图使用此代码清除缓存,但它不与谷歌Chrome工作。我需要清除浏览器中的所有缓存或清除所有网站缓存(不只是一个页面)Ps:大多数代码使用小部件DOJO javascript,这就是为什么我需要清除所有缓存。

List<string> keys = new List<string>();
// retrieve application Cache enumerator
IDictionaryEnumerator enumerator = Cache.GetEnumerator();
// copy all keys that currently exist in Cache
while (enumerator.MoveNext())
{
  keys.Add(enumerator.Key.ToString());
}
// delete every key from cache
for (int i = 0; i < keys.Count; i++)
{
  Cache.Remove(keys[i]);
}
HttpRuntime.Close();

谢谢大家的回答。

如何使用ASP.net(c#)清除浏览器中的所有缓存

您可以尝试这样清除浏览器的所有缓存

HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Expires", "0");

你也可以参考:确保网页不被缓存,在所有浏览器