Question

In my ASP.NET MVC 2 application I've decorated an action with the following attributes.

[ETag]
[OutputCache(Duration = 604800, VaryByParam = "none", Location = OutputCacheLocation.Any)]
public ActionResult Index()

(for the ETag attribute I've used the attribute class found here.)

I've also added the following to my 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="&quot;&quot;" />
  </customHeaders>
</httpProtocol>

<!-- Expiry -->
<staticContent>
  <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>

My problem is that when I load the page from my hosting server and view the header in Firebug I receieve an ETag, but no cache expiry.

Cache-Control   private
Content-Type    text/html; charset=utf-8
Etag    HKQ9Pp6hFTMRZYZbbIi3HA==,""
Server  Microsoft-IIS/7.0
X-AspNetMvc-Version 2.0
X-AspNet-Version    4.0.30319
X-Powered-By    ASP.NET
Date    Tue, 06 Sep 2011 18:31:05 GMT
Content-Length  4447

When I load the page locally the response does not have an ETag, but does have "Cache-Control" and "Expires" fields set.

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

Also, note that although I'm setting gzip compression in the web.config, it doesn't appear in either of the response headers.

So why do the settings in my web.config file appear to be ignored part of the time? Is it possible that my hosting server overrides these? If so, it doesn't make much sense for them to remove the cache or compression settings, does it?

Was it helpful?

Solution

I eventually found that this problem was being caused by my host server company configuring IIS to only pass the Etag if a page is requested more than twice-a-second.

Therefore the code above would normally work but some information was being removed when leaving the server, which seems the wrong thing to do but it explains what was happening.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top