Sunday, February 5, 2012

Add Expires Headers In Asp.NET

In this example i am Explaining how to add or set expires headers for static files or images in asp.net 2.0, 3.5

Performance is the main concern for any asp.net web application and bit of this can be achieved by setting expires headers for static files and images which doesn't change too often.


Add Expires Headers In asp.net 2.0 3.5


when expires headers are set for a future date or to never expires then browser fetch these files from cache and doesn't need to download these files every time application is loaded in browser, hence site or application is loaded faster




To do this we need to add code mentioned below in web.config file of asp.net web application

Set Expires headers to future date

<configuration>
    <system.webserver>
        <staticcontent>
            <clientcache cachecontrolcustom="" cachecontrolmode="UseExpires" httpexpires="Thu, 31 Dec 2020 00:00:00 GMT">
        </clientcache></staticcontent>
    </system.webserver>
</configuration>

Add headers to expire after certain days

<configuration>
  <system.webserver>
    <staticcontent>
      <clientcache cachecontrolmaxage="150.00:00:00" cachecontrolmode="UseMaxAge">
    </clientcache></staticcontent>
  </system.webserver>
</configuration>

Now the file headers will expire after 150 days


Hope this helps

0 comments:

Post a Comment