IE 8和客户端缓存 [英] IE 8 and client-side caching

查看:193
本文介绍了IE 8和客户端缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

故事背景:

我有一个IIS 6 Web服务器上的.NET 3.5的门户网站。目前有被赋予一个值,并根据该值查找上的web服务的PDF文件,并​​显示在网页另一标签的结果给用户的页面。这是一个具有以下code完成的。

I have a web portal in .NET 3.5 on an IIS 6 web server. Currently there is a page that is given a value and based on that value looks up a PDF file on a web service and displays the results to the user in another tab in the web page. This is done with the following code.

 context.Response.ClearContent();
 context.Response.ClearHeaders();
 context.Response.Clear();
 context.Response.AddHeader("Accept-Header", pdfStream.Length.ToString());                                               
 context.Response.ContentType = "application/pdf";
 context.Response.BinaryWrite(pdfStream.ToArray());
 context.Response.Flush();

此工作,并已工作多年。然而,我们得到了一个特定的客户端是具有PDF,直到它们被清除临时Internet缓存每次都返回相同的PDF客户端的问题。

This works and has worked for years. However we got an issue from the client that a particular client was having the PDF returned as the same PDF every time until they cleared temp internet cache.

我想爽哦,这是一个轻松的一年。我刚才添加的缓存头,以应对从未进行缓存。所以我添加以下内容:

I thought oh cool, this is an easy one. I will just add the cache headers to the response to never cache it. So I added the following:

context.Response.Cache.SetCacheability(HttpCacheability.NoCache);//IE set to not cache
context.Response.Cache.SetNoStore();//Firefox/Chrome not to cache
context.Response.Cache.SetExpires(DateTime.UtcNow); //for safe measure expire it immediately 

快速测试我有什么,我期待在响应头。之后

After a quick test I got exactly what I was expecting in the response header.

Cache-Control    no-cache, no-store 
Pragma    no-cache 
Expires    -1 

问题:

所以这个去住。一切似乎一个凉爽的一天。之后的日子,咣当,大家都开始变得白屏幕,没有显示PDF。经过进一步调查,我发现这是只有IE 6,7,8。 Chrome是精细,精细的Firefox和Safari罚款,甚至是IE 9的罚款。不知道为什么会这样,我恢复了我的变化,并部署它,一切又重新开始工作。

So this went live. Everything seemed cool day one. The day after, bam, everyone started getting white screens and no PDF displayed. After further investigation, I found out it was only IE 6,7,8. Chrome is fine, Firefox fine, safari fine, even IE 9 fine. Without knowing the why this happened, I reverted my change and deployed it, and everything started worked again.

我已经找遍了试图找出为什么我的缓存头似乎混淆IE 6-8无济于事。有没有人经历了与IE 6-8此类问题?有我丢失的东西?感谢您的任何见解。

I have searched all over trying to find out why my caching headers seemed to confuse IE 6-8 to no avail. Has anyone experienced this type of issue with IE 6-8? Is there something I am missing? Thanks for any insight.

推荐答案

我找到了解决办法。以下是放倒我。 这里是一个链接

I found the solution. Here is what tipped me off. Here is a link

基本上IE8(或更低)是有与Cache-Control头的问题,如果它有无缓存存储缓存。我能够通过基本上只允许私有缓存来解决问题,并设置一个最大年龄很短,因此几乎立即过期。

Basically IE8 (and lower) was having issues with the Cache-Control header if it had no-cache or store-cache. I was able to work around the problem by basically allowing private caching only and set a max age to very short so it expires almost immediately.

//Ie 8 and lower have an issue with the "Cache-Control no-cache" and "Cache-Control store-cache" headers.
//The work around is allowing private caching only but immediately expire it.
if ((Request.Browser.Browser.ToLower() == "ie") && (Request.Browser.MajorVersion < 9))
{
     context.Response.Cache.SetCacheability(HttpCacheability.Private);
     context.Response.Cache.SetMaxAge(TimeSpan.FromMilliseconds(1));
}
else
{
     context.Response.Cache.SetCacheability(HttpCacheability.NoCache);//IE set to not cache
     context.Response.Cache.SetNoStore();//Firefox/Chrome not to cache
     context.Response.Cache.SetExpires(DateTime.UtcNow); //for safe measure expire it immediately
}

这篇关于IE 8和客户端缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆