ASP.NET MVC3 IIS7.5:缓存控制最大值始终为0(不利于客户端缓存) [英] ASP.NET MVC3 IIS7.5: Cache-Control maxage is always 0 (not good for client-side caching)

查看:71
本文介绍了ASP.NET MVC3 IIS7.5:缓存控制最大值始终为0(不利于客户端缓存)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Fiddler上测试我的网站,发现Web服务器始终返回

I was testing my website with Fiddler and noticed that web server always returns

Cache-Control: private, s-maxage=0

用于动态内容(MVC操作).这样可以防止页面在客户端缓存.我想知道这是MVC还是IIS的问题.我该如何解决?我确实需要客户端缓存才能工作.

for dynamic content (MVC actions). This prevents pages from being cached on client side. I wonder if it is problem of MVC or IIS. How can I fix it? I really need client-side caching to work.

谢谢!

P.S.以下是完整的响应标头集:

P.S. Below is the full set of response headers:

HTTP/1.1 200确定 缓存控制:私有,s-maxage = 0 内容类型:text/html;字符集= utf-8 内容编码:gzip 有所不同:接受编码 伺服器:Microsoft-IIS/7.5 X-AspNetMvc版本:3.0 X-AspNet版本:4.0.30319 与X-UA兼容:IE = edge,Chrome = 1 日期:2011年11月20日,星期日,格林尼治标准时间 内容长度:2050

HTTP/1.1 200 OK Cache-Control: private, s-maxage=0 Content-Type: text/html; charset=utf-8 Content-Encoding: gzip Vary: Accept-Encoding Server: Microsoft-IIS/7.5 X-AspNetMvc-Version: 3.0 X-AspNet-Version: 4.0.30319 X-UA-Compatible: IE=edge,Chrome=1 Date: Sun, 20 Nov 2011 23:07:46 GMT Content-Length: 2050

推荐答案

使用 Controller和/或操作上的> OutputCacheAttribute ,以设置该控制器的操作或特定操作的缓存策略.

Use the OutputCacheAttribute on your controllers and/or actions to set the cache policy for that controller's actions or a particular action.

 [OutputCache( Location = OutputCacheLocation.Client, Duration = 600 )]
 public class HomeController : Controller
 {
    ..
 }

这篇关于ASP.NET MVC3 IIS7.5:缓存控制最大值始终为0(不利于客户端缓存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆