cache static images by keeping Cache-Control set to no cache in asp.net mvc

时间:2017-06-09 12:49:52

标签: asp.net-mvc security web-config cache-control outputcache

I have images in my ~/Content/Images folder. And these images are used in Layout and other pages. When i request a page "Contact", it loads images referenced on that page and i can see requests in IIS log for each image load. This is ok for the first request. and for 2nd and further requests to contact page, i do not want these images to be requested from server again, want them to be load from cache.

I don’t want to change security settings in my web.config

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Cache-Control" value="no-cache, no-store" />
      <add name="Pragma" value="no-cache" />
      <add name="Expires" value="-1" />
    </customHeaders>
  </httpProtocol>
</system.webServer>

I am trying to add output cache setting for images as

<system.webServer>
  <caching>
    <profiles>
      <add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="DontCache" location="Client" />
      <add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="DontCache" location="Client" />
      <add extension=".jpeg" policy="CacheUntilChange" kernelCachePolicy="DontCache" location="Client" />
      <add extension=".png" policy="CacheUntilChange" kernelCachePolicy="DontCache" location="Client" />
    </profiles>
  </caching>
  <staticContent>
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
  </staticContent>
</system.webServer>

But above setting still sending a requests for images each time I am refreshing the page.

do not want session values to be cached so I set cache-control to no-cache.

I want to stop these requests for static images until I change it. What i am missing here?

0 个答案:

没有答案