背景故事:
我在IIS3.5Web服务器上有一个.NET 3.5中的门户网站。目前,有一个页面被赋予一个值,并基于该值在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();这是可行的,而且多年来一直有效。然而,我们从客户端得到一个问题,就是在每次清除临时internet缓存之前,特定的客户端都会将PDF作为相同的PDF返回。
我想,哦,酷,这是一个简单的。我只需将缓存头添加到响应中,就不会缓存它。因此,我添加了以下内容:
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显示。经过进一步调查,我发现只有IE6,7,8。Chrome是罚款,Firefox罚款,safari罚款,甚至IE9罚款。在不知道发生这种情况的原因的情况下,我返回了我的更改并进行了部署,一切都重新开始了。
我到处搜索,试图找出为什么我的缓存头似乎混淆了IE6-8,但没有效果。有人经历过IE6-8的这类问题吗?我遗漏了什么吗?谢谢你的见解。
发布于 2011-12-02 17:30:52
我找到了解决办法。这是我的线索。Here is a link
基本上,如果IE8有no-cache或store-cache,那么它(以及更低的)就会出现缓存控制头的问题。我能够解决这个问题,基本上只允许私有缓存,并将最大时间设置为非常短,因此它几乎立即过期。
//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
}https://stackoverflow.com/questions/8348214
复制相似问题