简体   繁体   中英

ASP.NET staticContent configuration option not working

I've got an ASP.NET site running under VS10 Dev server. I'd like for certain static content files to be served with a long max-age cache directive, but can't seem to get it working.

I have this in my web.config:

<system.webServer>
<caching enabled="true" enableKernelCache="true">    
</caching>
<httpProtocol>
  <customHeaders>
    <remove name="X-Powered-By" />
  </customHeaders>
</httpProtocol>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>    

And in folder of content to cache

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
          <clientCache cacheControlMode="UseMaxAge" 
cacheControlMaxAge="30.00:00:00" />
        </staticContent>
      </system.webServer>
    </configuration>

But it doesn't work either, it always serves with Cache-Control: private

So, is this staticContent configuration supported? If not, any workarounds? If so, what am I missing?

Headers i get in all requests:

Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 23 Feb 2012 20:47:56 GMT
Cache-Control: private
Content-Type: application/octet-stream
Content-Length: 1043
Connection: Close

I resolved this problem! In Web.config turn on authentication section to FormsAuthentication.

This was very helpful. I don't normally post comments, but in this case, I thought it would help others. In my case, the cache-control was set to private, and I could not modify it. The obscure answer was I had authentication turned on, when I didn't need or want it. I will say that it took much longer to get a hint from search engines, maybe this text will help.

I solved this problem! In Web.config turn on authentication section to FormsAuthentication.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM