views:

132

answers:

1

What is the best approach to caching images in asp.net?

+3  A: 

Where do you want to cache them?

If you want users/proxies to cache your site's images, the best way to do that would be to set up the caching in IIS on the folders containing your static content (images/JS/css), with suitable cache-busting strategies in place to ensure that if you do update them the calling clients get the latest versions.

In IIS 6 and below, you can do this by:

  1. Open IIS Manager.
  2. Expand the websites until you find your site, and the folder containing your images.
  3. Right click on the folder and select properties.
  4. Select the HTTP Headers tab.
  5. Check "Enable content expiration", and set the cache time in the "Expire after" section.
  6. Ok out of all the dialogues.

In IIS 7 you can do this by:

  1. Open IIS Manager.
  2. Expand the websites until you find your site, and the folder containing your images.
  3. Click on the folder in the section headed "IIS" double click on "HTTP Response Headers".
  4. Click on "Set Common Headers..." in the "Actions" pane.
  5. Check "Expire Web content", and set the cache time in the "After" section.
  6. Ok out of all the dialogues.
Zhaph - Ben Duguid
Thanks Zhaph. it works great
Pragnesh Patel
No problem, glad to help.
Zhaph - Ben Duguid