I'm trying to add a "max-age" header to my response. It works fine on my Visual Studio Development Server, but as soon as I move the app to IIS (tried both IIS express locally and IIS on the server) - the header disappears.
My code:
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0, 0));
VS Dev server response (all works just fine):
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 07 Jan 2011 14:55:04 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: public, max-age=86400
IIS7 Response
HTTP/1.1 200 OK
Server: Microsoft-IIS/7.5
Date: Fri, 07 Jan 2011 15:00:54 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: public
PS. It's an ASHX-handler, if it matters...
Solution:
in
web.config
:and en IIS PC:
With cmd go to
c:\windows\system32\inetsrv
.Then execute:
UPDATE: 2011-03-14 The fix is ensure you call SetSlidingExpiration(true)
If you remove the OutputCache module you will get the desired result. I see this as a bug.
So, in your web.config you would do the following:
ADDED: So, there's additional information.
The following strips the s-maxage
The following strips the s-maxage
This does NOT - go figure...
Belated answered but this could help someone :-