So I have got an ASP.NET MVC 5 site running on IIS 10 locally on my Windows 10 laptop, with the following settings in web.config.
Compiled in Release configuration, debug mode off:
<compilation debug="false" targetFramework="4.5.2" />
and a Cache-Control header using max-age:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
But no matter what I do, I always see Cache-Control: private
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
I've turned off all modules I had and ran a failed trace request, which showed the header is being set:
But I can't track down anything about this ManagedPipelineHandler which appears to be the module in which the header is set.
I tried adding Cache-Control as a custom header:
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<remove name="Cache-Control" />
<add name="Cache-Control" value="public, max-age=1800, must-revalidate" />
</customHeaders>
</httpProtocol>
But this only appended onto the existing private setting:
HTTP/1.1 200 OK
Cache-Control: private,public, max-age=1800, must-revalidate
Content-Type: text/html; charset=utf-8
My runAllManagedModulesForAllRequests setting is false which other posts have suggested might be the cause.
I know I can set this header in code but I'd love to know what & why is forcing the "private" setting.
Can anyone advise?
UPDATE
Something is forcing responses to have cache-control: private in IIS7
So this is default behaviour for .NET when there's no output cache used for a request (and you have output cache enabled). If you set the sendCacheControlHeader attribute to false for & in web.config - you don't get the Cache-Control: private header!
Oddly you still don't get the correct Cache-Control header based on the node - but you control the header via the section, so this now works:
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<add name="Cache-Control" value="max-age=30,public" />
</customHeaders>
</httpProtocol>