【发布时间】: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。
【问题讨论】:
-
使用处理程序与使用服务非常相似,因为我可以在两者中做所有相同的事情,所以上述内容根本无法解决我的问题。
标签: c# wcf http-headers