【问题标题】:HTTP headers for preventing caching in Firefox using C# and wcf使用 C# 和 wcf 在 Firefox 中防止缓存的 HTTP 标头
【发布时间】:2011-10-14 00:10:07
【问题描述】:

我有一个提供图像的 wcf 服务,这些图像是不稳定的并且会定期更新。我使用 img 标签将它们显示在网页上

<img src="location/map/image/{coordinates} 

坐标是一个数字,例如12786。 在我的 javascript 中,我在不同时间创建和删除图像标签。我已使用以下代码添加 HTTP 标头以防止缓存

    //whatever the result we will not cache this at the client or intermediate proxies
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
    HttpContext.Current.Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
    HttpContext.Current.Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
    HttpContext.Current.Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
    HttpContext.Current.Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1 
    //write the image http response

我注意到,在 Firefox 中,图像永远不会重新刷新,而是求助于添加一个虚拟查询字符串参数。我已经明白,firefox DOM 会注意到该图像 url 之前已在同一页面上使用过,并且不会刷新它。

这似乎完全违反了 Http(REST),因为图像无论如何都没有链接到文档,并且是一个单独的 HTTP 资源,为什么它的可访问性应该由它所引用的页面/DOM 来确定。

这完全违反了 HTTP。

我的问题是;有没有办法在使用 HTTP 的 Firefox 中防止这种行为?请不要说Response.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);它在FF上不起作用。

我正在使用FF6。

【问题讨论】:

  • 这可能对你有帮助:stackoverflow.com/questions/5063338/…
  • 使用处理程序与使用服务非常相似,因为我可以在两者中做所有相同的事情,所以上述内容根本无法解决我的问题。

标签: c# wcf http-headers


【解决方案1】:

尝试添加以下内容:

HttpContext.Current.Response.AppendHeader("Pragma", "no-cache"); 
HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache");

HttpContext.Current.Response.CacheControl = "no-cache"; 
HttpContext.Current.Response.Expires = -1;

HttpContext.Current.response.ExpiresAbsolute = new DateTime(1900, 1, 1); 
HttpContext.Current.response.Cache.SetCacheability(HttpCacheability.NoCache);

【讨论】:

  • 适用于 IE、Chrome 但不适用于 FF
  • 那么在服务器上设置变量是不可能的。如果 FF 不公平,那么我会将当前时间戳附加到请求中。 (但我记得我在 IE7 中遇到过这个问题)
【解决方案2】:

好的,我需要关闭它,结果是FF需要修复,我会在FF网站上添加一个错误。

感谢所有回答并查看此问题的人,希望这对将来的一些谷歌用户有所帮助。

【讨论】:

    猜你喜欢
    • 2023-04-08
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    • 2017-01-30
    • 1970-01-01
    相关资源
    最近更新 更多