Asp.net IE 8和客户端缓存

Asp.net IE 8和客户端缓存,asp.net,internet-explorer,http,iis,caching,Asp.net,Internet Explorer,Http,Iis,Caching,背景故事: 我在IIS 6 web服务器上的.NET 3.5中有一个web门户。当前有一个页面给定了一个值,并基于该值在web服务上查找PDF文件,并在web页面的另一个选项卡中向用户显示结果。这是通过以下代码完成的 context.Response.ClearContent(); context.Response.ClearHeaders(); context.Response.Clear(); context.Response.AddHeader("Accept-Header", p

背景故事:

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

 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 
问题:

所以这部电影开始了。第一天一切似乎都很酷。第二天,砰的一声,每个人都开始看到白色屏幕,没有显示PDF。经过进一步的调查,我发现只有IE 6,7,8。Chrome很好,Firefox很好,safari很好,甚至IE 9也很好。在不知道为什么会发生这种情况的情况下,我恢复了我的更改并部署了它,然后一切又开始工作了


我已经搜索了所有地方,试图找出为什么我的缓存头似乎混淆了IE 6-8,但没有结果。有没有人在IE 6-8中遇到过这种问题?我有什么遗漏吗?谢谢你的帮助。

我找到了解决方案。这是我得到的消息

基本上,如果IE8(及更低版本)具有
无缓存
存储缓存
,则它的缓存控制头会出现问题。我可以通过基本上只允许私有缓存来解决这个问题,并将max age设置为极短,这样它几乎可以立即过期

//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及更低版本的“缓存控制无缓存”和“缓存控制存储缓存”标题存在问题。
//解决方法是只允许私有缓存,但会立即使其过期。
if((Request.Browser.Browser.ToLower()=“ie”)&&(Request.Browser.MajorVersion<9))
{
context.Response.Cache.SetCacheability(HttpCacheability.Private);
context.Response.Cache.SetMaxAge(TimeSpan.frommilluses(1));
}
其他的
{
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);//IE设置为不缓存
context.Response.Cache.SetNoStore();//Firefox/Chrome不缓存
context.Response.Cache.SetExpires(DateTime.UtcNow);//为了安全起见,立即将其过期
}

感谢您发布此邮件。我浪费了那么多的时间和很多的挫败感试图弄明白这一点。