.net - ASP.NET MVC : OutputCache and http headers

标签 .net asp.net asp.net-mvc caching http-headers

我刚刚开始在我的一些 Controller 操作上使用 OutputCache,但我并没有得到我期望的响应。

我已将缓存时间设置为 5 分钟,并且 Expires header 的出现与 Last-Modified header 相同,即发出请求的时间。

这是我目前得到的标题:

Date                    Thu, 16 Jul 2009 06:35:07 GMT
Server                  Microsoft-IIS/6.0
X-Powered-By            ASP.NET
X-AspNet-Version        2.0.50727
X-AspNetMvc-Version     1.0
Content-Encoding        gzip
Cache-Control           public, max-age=300
Expires                 Thu, 16 Jul 2009 06:35:06 GMT
Last-Modified           Thu, 16 Jul 2009 06:35:03 GMT
Vary                    *
Content-Type            text/html; charset=utf-8
Content-Length          575

这是我期望的标题:
Date                    Thu, 16 Jul 2009 06:35:07 GMT
Server                  Microsoft-IIS/6.0
X-Powered-By            ASP.NET
X-AspNet-Version        2.0.50727
X-AspNetMvc-Version     1.0
Content-Encoding        gzip
Cache-Control           public, max-age=300
Expires                 Thu, 16 Jul 2009 06:40:06 GMT
Last-Modified           Thu, 16 Jul 2009 06:35:03 GMT
Vary                    *
Content-Type            text/html; charset=utf-8
Content-Length          575

关于为什么要这样做的任何想法?

干杯
安东尼

最佳答案

max-age优先(来自 RFC 2616 ):

We use the term expires_value to denote the value of the Expires header. We use the term max_age_value to denote an appropriate value of the number of seconds carried by the "max-age" directive of the Cache-Control header in a response (see section 14.9.3).

The max-age directive takes priority over Expires, so if max-age is present in a response, the calculation is simply:

  freshness_lifetime = max_age_value 

Otherwise, if Expires is present in the response, the calculation is:

  freshness_lifetime = expires_value - date_value


所以客户端应该像你期望的那样使用缓存版本。

关于.net - ASP.NET MVC : OutputCache and http headers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1135807/

相关文章:

c# - 如何在asp.net core 6中添加全局路由前缀

c# - .NET GUI 应用程序中的 Console.Write

asp.net - 我可以使用 Mono 和 mod_mono 托管 ASP.NET MVC 网站吗?

ASP.NET Web API 私有(private) Controller

asp.net-mvc - SqlParameter 与 ObjectParameter

c# - protobuf-net 是否支持 System.Collections.Queue?

c# - 如何用 Unicode 转换特殊字符?

没有名字的 ASP.NET 网页,比如 stackoverflow?

asp.net - 通过 jQuery AJAX 加载 ASP.Net 用户控件

mysql - 将数据绑定(bind)到 GridView