使用下面给出的任意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>标头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);帮不上忙。强制不发送标头的唯一方法是使用直接属性
[OutputCache(Duration = 60, VaryByParam = "", Location = OutputCacheLocation.Any)]
public ActionResult Index()我做错了什么?我更喜欢使用CacheProfiles,因为这些可以在web.config中修改。
这里发布的头文件来自Cassini (服务器: ASP.NET Development Server/10.0.0.0),但我在Windows2008上的IIS7中也看到了相同的结果。
发布于 2012-11-22 17:40:34
对于amit_g来说,这可能有点晚了,但是对于其他正在寻找答案的人来说,您可以在配置中指定一个应用程序范围的输出缓存设置,以删除Vari.*响应头。
<caching>
<outputCache omitVaryStar="true" />
<outputCacheSettings>
<outputCacheProfiles>
...
</outputCacheProfiles>
</outputCacheSettings>
</caching>发布于 2015-02-03 07:04:51
请注意,对SetOmitVaryStar使用"true“是省略value:*头的正确值(不是false,这不会省略它)。
使用下面的代码对我很有效:
This.Response.Cache.SetOmitVaryStar(真);
https://stackoverflow.com/questions/9573501
复制相似问题