开发者

HTTP headers for preventing caching in Firefox using C# and wcf

开发者 https://www.devze.com 2023-04-13 02:08 出处:网络
I have a wcf service serving images, these images are volatile and regularly updated. I display them on a webpage using an img tag

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 
    HttpCo开发者_如何学Cntext.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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消