ASP.NET MVC3 IIS7.5: Cache-Control maxage is alway

2019-07-03 23:36发布

问题:

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

Cache-Control: private, s-maxage=0

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.

Thank you!

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

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

回答1:

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
 {
    ..
 }