IIS 8.5 MVC5 Client Cache is ignored

霸气de小男生 提交于 2019-12-06 07:49:51

问题


TL;DR - I want the server (IIS 8.5) to return 304 not modified for the CSS and JS bundles.

I've been unable to get IIS 8.5 to honor the clientCache settings in web.config. No matter what I do, I can't seem to get it to cache the static content. This is a MVC5 app in VS2013. I've got all the static files in a folder "Assets".

The request looks like: http://someserver/AppName/Assets/mainjs?v=FNj_9ZPAbYVAQsyDo2F8XUnWv5NQpY4iX2RGu4NpJ5g1

  1. Attempt #1, place a new web.config in the Assets folder with the following:
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>
  1. Attempt #2: place this following configuration in the root web.config
<staticContent>   
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />    
</staticContent>
  1. Attempt #3: trying setting the cache using the location tag
<location path="Assets">
  <system.webServer>
    <staticContent>
      <clientCache  cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
    </staticContent>
  </system.webServer>
</location>

Here are the things I've tried in IIS 8.5 manager. Under the Default Web Site/TestApp

  1. HTTP Requeset Headers, Set Common HTTP Headers, check "Expire Web Content" "After 365 Day(s)".
  2. Apply the same setting to the "Assets" folder

I've tried these steps each on their own and all together and every other which way. No matter what, it won't add the max-age value to Cache-Control.

For each of these, the browswer returns 200 responses for the CSS and JS bundles. I cannot get the server cache the content coming from the Assets folder.

Cache-Control:private
Content-Encoding:gzip
Content-Length:22591
Content-Type:text/css; charset=utf-8
Date:Mon, 02 Feb 2015 21:49:49 GMT
Expires:Tue, 02 Feb 2016 21:49:49 GMT
Last-Modified:Mon, 02 Feb 2015 21:49:49 GMT
Persistent-Auth:true
Server:Microsoft-IIS/8.5
Vary:Accept-Encoding
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET

回答1:


Check the individual files of the bundle. What do the files look like when you turn off optimizations? After you register your Bundles make a call to :

BundleTable.EnableOptimizations = (!HttpContext.Current.IsDebuggingEnabled);

OR

BundleTable.EnableOptimizations = false;

It could be that each file is coming back with a not modified. Does the status change when you refresh while in a debug session?



来源:https://stackoverflow.com/questions/28288192/iis-8-5-mvc5-client-cache-is-ignored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!