asp.net – IE 8和客户端缓存

背景故事:

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

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返回,直到他们清除临时Internet缓存.

我觉得很酷,这很容易.我只是将缓存标头添加到响应中,从不缓存它.所以我添加了以下内容

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

经过快速测试后,我得到了我在响应标题中所期待的内容.

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

问题:

所以这就开始了.一天看起来很酷.第二天,bam,每个人都开始获得白色屏幕并且没有显示PDF.经过进一步调查,我发现它只是IE 6,7,8. Chrome很好,Firefox很好,Safari很好,甚至IE 9还不错.在不知道发生这种情况的原因的情况下,我恢复了我的改变并进行了部署,一切都恢复了.

我一直在搜索,试图找出为什么我的缓存标题似乎混淆IE 6-8无济于事. IE 6-8有没有人遇到过这类问题?有什么我想念的吗?感谢您的任何见解.

解决方法

我找到了解决方案.这是让我失望的原因. Here is a link

基本上IE8(及更低版本)如果没有缓存或存储缓存,则遇到Cache-Control标头问题.我能够通过基本上只允许私有缓存来解决问题,并将最大年龄设置为非常短,因此它几乎立即到期.

//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
}

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....