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

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

问题描述

背景故事:

我在 IIS 6 Web 服务器上的 .NET 3.5 中有一个 Web 门户.目前有一个页面被赋予一个值,并基于该值在 Web 服务上查找 PDF 文件,并在网页的另一个选项卡中向用户显示结果.这是通过以下代码完成的.

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 作为相同的 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(及更低版本)具有 no-cachestore-cache,则 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天全站免登陆