views:

403

answers:

1

Using asp.net in visual studios and IIS7 when i get a host.

I have a folder full of icons that will rarely change and is used on every page. Is there a way i can set a certain directory to expire something like once every 2 or so hours so i can decrease the amount of incoming request to the server?

+3  A: 

You do that in IIS. If you are using IIS 7, you can add the header in your web.config. It’s in the system.webServer section.

<staticContent>
    <clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>

This will cause all static content to have an expires HTTP header set to the year 2020. Static content means anything that isn’t served through the ASP.NET engine such as images, script files and styles sheets.

Or to use a relative expiration, use this:

<staticContent>
    <clientCache cacheControlMaxAge ="2.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>

This will cause all static content to have an expires HTTP header set to 2 days.

Gabriel McAdams
How do i say check back in 4 hours or of midnight of every day? I'd like holiday themes and such.
acidzombie24
If you want to have the ability to change images at any time, there are 2 options. 1) Use the above method, and change the URL when you change images, and change them back at the end of the holiday. 2) Set the expires date smaller.
Gabriel McAdams
This looks like a fixed date. Cant i set it relative or use code to change it?
acidzombie24
I added how to make it relative to my answer
Gabriel McAdams
Great answer! It just solved my problems, thanks!
Django Reinhardt