使用OutputCacheProfiles时如何抑制标头Vary:* [英] How to supress header Vary:* when using OutputCacheProfiles
问题描述
使用下面提供的任何OutputCacheProfiles
Using any of the OutputCacheProfiles given 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>
标题变化:*总是发送
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 the request to the server and not cache locally. Even using
this.Response.Cache.SetOmitVaryStar(false);
没有帮助.我可以强制不发送标头的唯一方法是使用直接属性
doesn't help. The only way I can force the header not to be sent is to use direct attribute
[OutputCache(Duration = 60, VaryByParam = "", Location = OutputCacheLocation.Any)]
public ActionResult Index()
我做错了什么?我希望使用CacheProfile,因为可以在web.config中对其进行修改.
What am I doing wrong? I would prefer to use the CacheProfiles as those can be modified in the web.config.
此处发布的标头来自Cassini(服务器:ASP.NET Development Server/10.0.0.0),但我在Windows 2008的IIS 7中也看到了相同的结果.
The headers posted here are from the Cassini (Server: ASP.NET Development Server/10.0.0.0) but I have seen identical results in IIS 7 on Windows 2008 as well.
推荐答案
对于amit_g来说可能有点晚了,但是对于其他寻求答案的人,您可以在配置中指定应用程序范围的输出缓存设置以将其删除Vary.*响应标头.
It may be a bit late for amit_g, but for anyone else looking for an answer, you can specify an application-wide output cache setting in the config to remove the Vary.* response header.
<caching>
<outputCache omitVaryStar="true" />
<outputCacheSettings>
<outputCacheProfiles>
...
</outputCacheProfiles>
</outputCacheSettings>
</caching>
这篇关于使用OutputCacheProfiles时如何抑制标头Vary:*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!