Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache-Control Headers in ASP.NET not outputting max-age

I have this code:

 context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.Public);
 context.HttpContext.Response.Cache.SetMaxAge(TimeSpan.FromHours(24));

And the response is this:

Status Code: 200
Date: Fri, 14 Dec 2012 13:56:41 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 38436
X-AspNetMvc-Version: 4.0
Server: Microsoft-IIS/8.0
Content-Type: application/rss+xml; charset=utf-8
Cache-Control: public
X-SourceFiles: =?UTF-8?B?QzpcUHJvamVjdHNcVGVzdFxtYW5nb21pbnQucHVibGljXHNyY1xNYW5nb21pbnQuUHVibGljLldlYlxibG9nXHJzcw==?=

Why is there no max-age defined on Cache-Control?

like image 560
Jon Avatar asked Dec 26 '22 13:12

Jon


1 Answers

I had the same problem and it was driving me nuts. The solution is to add this line first:

context.HttpContext.Response.Cache.SetSlidingExpiration(true);
like image 113
Todd Menier Avatar answered Feb 16 '23 07:02

Todd Menier