Asp.net mvc ASP.NET MVC-缓存和;web.config中的压缩设置并不总是被使用
在我的ASP.NETMVC2应用程序中,我用以下属性修饰了一个动作Asp.net mvc ASP.NET MVC-缓存和;web.config中的压缩设置并不总是被使用,asp.net-mvc,caching,web-config,etag,http-compression,Asp.net Mvc,Caching,Web Config,Etag,Http Compression,在我的ASP.NETMVC2应用程序中,我用以下属性修饰了一个动作 [ETag] [OutputCache(Duration = 604800, VaryByParam = "none", Location = OutputCacheLocation.Any)] public ActionResult Index() (对于ETag属性,我使用了找到的属性类。) 我还将以下内容添加到我的web.config中 <!-- gzip compression --> <httpCo
[ETag]
[OutputCache(Duration = 604800, VaryByParam = "none", Location = OutputCacheLocation.Any)]
public ActionResult Index()
(对于ETag属性,我使用了找到的属性类。)
我还将以下内容添加到我的web.config中
<!-- gzip compression -->
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<!-- ETags -->
<httpProtocol>
<customHeaders>
<add name="ETag" value="""" />
</customHeaders>
</httpProtocol>
<!-- Expiry -->
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
本地加载页面时,响应没有ETag,但设置了“缓存控制”和“过期”字段
Server ASP.NET Development Server/10.0.0.0
Date Tue, 06 Sep 2011 18:33:55 GMT
X-AspNet-Version 4.0.30319
X-AspNetMvc-Version 2.0
Cache-Control private, max-age=604800
Expires Tue, 13 Sep 2011 18:33:54 GMT
Last-Modified Tue, 06 Sep 2011 18:33:54 GMT
Content-Type text/html; charset=utf-8
Content-Length 4447
Connection Close
另外,请注意,尽管我在web.config中设置了gzip压缩,但它不会出现在任何一个响应头中
那么,为什么我的web.config文件中的设置有时会被忽略呢?我的托管服务器是否可能覆盖这些?如果是这样,那么他们删除缓存或压缩设置就没有多大意义了,是吗?我最终发现这个问题是由我的主机服务器公司将IIS配置为仅在每秒请求页面两次以上时才通过Etag造成的
因此,上述代码正常工作,但在离开服务器时删除了一些信息,这似乎是错误的做法,但它解释了发生的情况。我最终发现,这个问题是由我的主机服务器公司将IIS配置为仅在每秒请求页面两次以上时才通过Etag造成的 因此,上面的代码正常工作,但在离开服务器时,一些信息被删除,这似乎是错误的,但它解释了发生了什么
Server ASP.NET Development Server/10.0.0.0
Date Tue, 06 Sep 2011 18:33:55 GMT
X-AspNet-Version 4.0.30319
X-AspNetMvc-Version 2.0
Cache-Control private, max-age=604800
Expires Tue, 13 Sep 2011 18:33:54 GMT
Last-Modified Tue, 06 Sep 2011 18:33:54 GMT
Content-Type text/html; charset=utf-8
Content-Length 4447
Connection Close