I have an asp.net web site and I would like the client browser to cache the HTML output of aspx pages once it gets them.
From reading around I found out that IIS7 does not support this out-of-the-box, so I added the following code to the OnLoad
event of my main master page:
protected override void OnLoad(EventArgs e) {
DateTime dt = DateTime.Now.AddDays(10);
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(dt);
Response.Cache.SetMaxAge(new TimeSpan(dt.Ticks - DateTime.Now.Ticks));
base.OnLoad(e);
}
With this I still get the following in the response header:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: -1
Vary: Accept-Encoding
Date: Fri, 05 Jul 2013 14:25:03 GMT
Content-Length: 10201
Maybe I did something a long time ago to override this, but I can't, for the life of me remember if and what I did. Not finding any info on this when searching Google makes me think that maybe cache-control
for aspx pages is not a good idea... but I need this in order for cloudfront (a CDN) to allow whole site delivery.