How to suppress Vary: * header when using OutputCacheProfiles

Using any of the OutputCacheProfiles below

<caching> <outputCacheSettings> <outputCacheProfiles> <clear/> <add name="CachingProfileParamEmpty" duration="87" varyByParam="" location="Any" /> <add name="CachingProfileParamNone" duration="87" varyByParam="None" location="Any" /> <add name="CachingProfileParamStar" duration="87" varyByParam="*" location="Any" /> </outputCacheProfiles> </outputCacheSettings> </caching> 

Vary header: * always sent

 HTTP/1.1 200 OK Server: ASP.NET Development Server/10.0.0.0 Date: Mon, 05 Mar 2012 20:11:52 GMT X-AspNetMvc-Version: 3.0 Cache-Control: public, max-age=87 Expires: Mon, 05 Mar 2012 20:13:13 GMT Last-Modified: Mon, 05 Mar 2012 20:11:46 GMT Vary: * Content-Type: text/html; charset=utf-8 Content-Length: 5368 Connection: Close 

which, in turn, causes the browser to send a request to the server and not cache locally. Even using

 this.Response.Cache.SetOmitVaryStar(false); 

Does not help. The only way I can make the header not send is to use the direct attribute

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

What am I doing wrong? I would prefer to use CacheProfiles, as they can be changed in the web.config file.

The headers posted here are for Cassini (Server: ASP.NET Development Server / 10.0.0.0), but I also saw identical results in IIS 7 in Windows 2008.

+3
asp.net-mvc asp.net-mvc-3 outputcache
source share
2 answers

It may be a little late for amit_g, but for anyone looking for an answer, you can specify the output cache setting for the entire configuration in config to remove the Vary response header. *.

 <caching> <outputCache omitVaryStar="true" /> <outputCacheSettings> <outputCacheProfiles> ... </outputCacheProfiles> </outputCacheSettings> </caching> 
+9
source share

Note that using "true" for SetOmitVaryStar is the correct value to omit the Vary: * header (not false, which will not omit it).

Using the following code for me:

this.Response.Cache.SetOmitVaryStar (true);

+3
source share

All Articles