Friday, January 21, 2011

IIS7 How to serve a default 404 image when an image is requested?

How can I get IIS7 to serve a default image instead of a 404 html page, when an image is requested?

e.g.

request for: http://www.example.com/myImage.jpg

myImage.jpg does not exist, so we deliver another image instead?

  • Consider URL Rewrite or something like that, although you'll need to do some extending for it to know if the jpg exists or not.

    You can use customErrors but that will affect all content type. Additionally, you could add your own HTTPHandler that watches for .jpg files, confirms that they don't exist, and serves up a default image it doesn't exist.

    Lucifer : Ok thanks, that is good advise and I had considered them, but was wondering if it was possible without rolling my own - thanks
    Scott Forsyth - MVP : No, I don't believe so. You can point all .jpg images to a single image, or all 404's to a single image, but there isn't something built-in that allows you throw a custom 404 just for .jpg files.

0 comments:

Post a Comment