【问题标题】:How to clear all cache in browser using ASP.net(C#)如何使用 ASP.net(C#) 清除浏览器中的所有缓存
【发布时间】:2015-09-22 05:03:08
【问题描述】:

我尝试使用此代码清除缓存,但它不适用于 Google 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();

感谢您的每一个回答。

【问题讨论】:

  • 我不认为你可以删除浏览器的缓存。它将非常浏览器浏览器。但是您可以为应用程序的资源设置缓存时间。

标签: c# asp.net dojo browser-cache


【解决方案1】:

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

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");

您也可以参考:Making sure a web page is not cached, across all browsers

【讨论】:

    猜你喜欢
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 2013-07-17
    相关资源
    最近更新 更多