使用下面给出的任何 OutputCacheProfiles
<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>
header Vary:* 总是被发送
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
这反过来导致浏览器将请求发送到服务器而不是本地缓存。即使使用
this.Response.Cache.SetOmitVaryStar(false);
没有帮助。我可以强制不发送 header 的唯一方法是使用直接属性
[OutputCache(Duration = 60, VaryByParam = "", Location = OutputCacheLocation.Any)]
public ActionResult Index()
我究竟做错了什么?我更喜欢使用 CacheProfiles,因为它们可以在 web.config 中修改。
此处发布的 header 来自 Cassini(服务器:ASP.NET Development Server/10.0.0.0),但我在 Windows 2008 上的 IIS 7 中也看到了相同的结果。
最佳答案
对于 amit_g 来说可能有点晚了,但对于其他任何人寻找答案,您可以在配置中指定应用程序范围的输出缓存设置以删除 Vary.* 响应 header 。
<caching>
<outputCache omitVaryStar="true" />
<outputCacheSettings>
<outputCacheProfiles>
...
</outputCacheProfiles>
</outputCacheSettings>
</caching>
关于asp.net-mvc - 如何抑制 header 变化 :* when using OutputCacheProfiles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9573501/