asp.net - Firefox 和 IE : Corrupted data when retrieved from cache

标签 asp.net caching http-headers etag

我对服务器有一个请求,如下所示:

http://localhost/Combine.aspx/flag/file1.js,file2.js,file3.js

我也试过这个:

http://localhost/Combine.aspx/flag/value/file1.js/file2.js/file3.js

它只是简单地组合了给定的三个文件:这工作正常。

根据 Firefox 的第一个请求,页面会正确显示。再次刷新页面时,内容是这样的:

��������`I�%&/m�{J�J��t��`$�����iG#)�*��eVe]f@�흼��{���{��;�N'

在那种情况下,没有向服务器发出请求,文件仅从 firefox 缓存中检索,据我所知。

如果我用 Control-F5 强制刷新页面,页面看起来又正常了。

这是使用 Control-F5 的请求和响应(在 firebug 中)(有效):

响应

Cache-Control   public
Content-Type    application/javascript; charset=utf-8
Content-Encoding    gzip
Expires Sun, 26 Feb 2012 02:57:26 GMT
Last-Modified   Fri, 07 Jan 2011 21:08:54 GMT
Etag    CLYvZwbFmainWEMi8h-6x-zNEIQ1
Vary    Accept-Encoding
Server  Microsoft-IIS/7.5
Set-Cookie  auth=longstring; path=/
X-AspNet-Version    2.0.50727
X-Powered-By    ASP.NET
Date    Thu, 03 Mar 2011 02:57:26 GMT
Content-Length  918

请求

Host    localhost
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.14) Gecko/20110218 Firefox/3.6.14
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Cookie  auth=longstring
Pragma  no-cache
Cache-Control   no-cache

这与 只是 F5 相同(不起作用):

响应:

Cache-Control   public
Content-Type    application/javascript; charset=utf-8
Content-Encoding    gzip
Expires Sun, 26 Feb 2012 02:57:26 GMT
Last-Modified   Fri, 07 Jan 2011 21:08:54 GMT
Etag    CLYvZwbFmainWEMi8h-6x-zNEIQ1
Vary    Accept-Encoding
Server  Microsoft-IIS/7.5
X-AspNet-Version    2.0.50727
X-Powered-By    ASP.NET
Date    Thu, 03 Mar 2011 03:01:31 GMT
Content-Length  1533

请求:

Host    localhost
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.14) Gecko/20110218 Firefox/3.6.14
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Cookie  auth=longstring

我唯一能说的是 Content-Length 不同(这可能会导致损坏),但由于它从未到达服务器,我无法控制它。

这可能是什么原因造成的?

编辑:

这也发生在 IE8 上,但它不是查看损坏的文件,而是下载损坏的文件。从未向服务器发出任何请求(在 visual studio 中设置断点)。

对于chrome,直接查看url时,每次都向服务器发起请求,每次都正常。不过,我相信,如果它包含在标签中,它的行为将类似于 Firefox。

哦,还有:

如果我关闭 Expires header (这是 URL 中的标志之一),一切正常

编辑 2:

我能够通过不发送两者 Expires 和 ETag header 来解决这个问题,只发送一个或另一个。不过,我不知道为什么 ETag header 会导致这种损坏。

最佳答案

这是因为您的 IIS 配置。将 IIS 调整为 ASP 4.0 Classic,而不是默认应用程序池

关于asp.net - Firefox 和 IE : Corrupted data when retrieved from cache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5176214/

相关文章:

c# - 如何在 ASCX 上设置控件的 Int 属性?

java - 我使用 POST 方法在 header 部分发送用户凭据

javascript - XMLHttpRequest 在 Chrome 扩展中修改了 Accept header

node.js - 如何避免使用 discord.js api 超过速率限制?

c# - 清除没有子元素的 xdt 元素

c# - 如何使用 ASP.NET C# 立即执行下载?

ios - AFNetworking不缓存HTTPS请求

c# - System.Runtime.Caching 不释放 BitmapImage 对象

docker - 从 Jenkinsfile 启动时,Gradle docker 容器忽略缓存

c# - 使用 asp.net core 1.0 的 https 上的 Kestrel