Add Expires Headers In Asp.NET

Add Expires Headers In Asp.NET 2.0,3.5,4.0 Using C# And VB.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


If you like this post than join us or share

2 comments:

Anonymous said...

This comment has been removed by a blog administrator.


Unknown said...

Unable to see the effect after applying the above setting in the web.config file.
ASP.net project still shows that expire header error in Y Slow


Find More Articles