asp.net-mvc - 如何抑制 header 变化 :* when using OutputCacheProfiles

标签 asp.net-mvc asp.net-mvc-3 outputcache

使用下面给出的任何 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/

相关文章:

asp.net - Windows Azure 上的简单文件上传

c# - 具有空值的 ASP.NET MVC 属性路由

asp.net-mvc - 隐藏日期时间的 ASP.NET MVC 格式

jquery - Ajax get/posts 后 IE 不刷新

c# - 始终使用 MVC3 和 Razor 输出原始 HTML

asp.net-mvc - ASP.NET MVC 缓存因 Controller 操作参数而异

javascript - 如何在 ASp.NET mvc 中使用 Jquery 将数组绑定(bind)到嵌套字段

asp.net - 我可以在 web.config 中为 maxJsonLength 设置无限长度吗?

c# - 自定义 OutputCache 提供程序不工作(调用 get 但未设置或添加)

c# - 如何在 MVC 5、C# 的 PartialView Controller 中使用 OutputCache?