如何通过asp.net-mvc的OutputCacheProfiles调整Vary:*实现响应头压缩?

2026-03-30 12:021阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计416个文字,预计阅读时间需要2分钟。

如何通过asp.net-mvc的OutputCacheProfiles调整Vary:*实现响应头压缩?

使用OutputCache配置缓存输出,可以通过以下方式:

- 添加缓存配置文件:`outputCacheProfiles`- 设置缓存参数:`caching`, `outputCacheSettings`- 添加或清除缓存配置:`outputCacheProfiles`, `clear`, `add` (例如:`name=CachingProfileParamEmpty, duration=87, varyByParam=, location=Any`)

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

标题变化:*始终发送

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开发服务器/ 10.0.0.0),但我在Windows 2008上的IIS 7中也看到了相同的结果.

对于amit_g可能有点迟,但对于寻找答案的其他人,您可以在配置中指定应用程序范围的输出缓存设置以删除Vary.*响应标头.

如何通过asp.net-mvc的OutputCacheProfiles调整Vary:*实现响应头压缩?

<caching> <outputCache omitVaryStar="true" /> <outputCacheSettings> <outputCacheProfiles> ... </outputCacheProfiles> </outputCacheSettings> </caching>

本文共计416个文字,预计阅读时间需要2分钟。

如何通过asp.net-mvc的OutputCacheProfiles调整Vary:*实现响应头压缩?

使用OutputCache配置缓存输出,可以通过以下方式:

- 添加缓存配置文件:`outputCacheProfiles`- 设置缓存参数:`caching`, `outputCacheSettings`- 添加或清除缓存配置:`outputCacheProfiles`, `clear`, `add` (例如:`name=CachingProfileParamEmpty, duration=87, varyByParam=, location=Any`)

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

标题变化:*始终发送

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开发服务器/ 10.0.0.0),但我在Windows 2008上的IIS 7中也看到了相同的结果.

对于amit_g可能有点迟,但对于寻找答案的其他人,您可以在配置中指定应用程序范围的输出缓存设置以删除Vary.*响应标头.

如何通过asp.net-mvc的OutputCacheProfiles调整Vary:*实现响应头压缩?

<caching> <outputCache omitVaryStar="true" /> <outputCacheSettings> <outputCacheProfiles> ... </outputCacheProfiles> </outputCacheSettings> </caching>