使用 C# 和 wcf 防止 Firefox 中缓存的 HTTP 标头
我有一个提供图像的 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。
我的问题是;有没有办法在 Firefox 中使用 HTTP 来防止这种行为?请不要说 Response.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); 它在 FF 上不起作用。
我用的是FF6
I have a wcf service serving images, these images are volatile and regularly updated. I display them on a webpage using an img tag
<img src="location/map/image/{coordinates}
cordinates is a number e.g. 12786.
In my javascript I create and remove the image tag at different times. I have used the following code to add HTTP headers to prevent caching
//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
I have noticed that in firefox the image is never refeshed and resorted to adding a dummy query string parameter. I have come to understand that firefox DOM will notice that the image url has been used before on the same page and won't refresh it.
This seems to be completely against Http(REST) since the image is not linked to the document in anyway and is a seperate HTTP resource why should it's accessibility be determined by the page/DOM it is referrenced in.
This is completely against HTTP.
My question is; is there a way of preventing this behaviour in firefox using HTTP? Please don't say Response.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
it doesn't work on FF.
I am using FF6.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试添加以下内容:
Try adding the following:
好吧,我需要关闭这个,结果是 FF 需要修复,我会在 FF 网站上添加一个错误。
感谢所有回答并查看这个问题的人,希望这对未来的谷歌用户有所帮助。
Ok I need to close this and the result is FF needs to be fixed, I will add a bug on the FF website.
Thanks to everyone who answered and looked at this question hopefully this will help some googler in future.