使用 C# 和 wcf 防止 Firefox 中缓存的 HTTP 标头

发布于 2024-12-09 21:33:58 字数 1704 浏览 0 评论 0原文

我有一个提供图像的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

从此见与不见 2024-12-16 21:33:58

尝试添加以下内容:

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

Try adding the following:

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);
苍白女子 2024-12-16 21:33:58

好吧,我需要关闭这个,结果是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文