JesseBuesking
JesseBuesking

Reputation: 6586

Missing Image Default

Is there a way (perhaps IIS, web.config, or other) where I can set a default image for missing images on a website? I'd like to send a custom image in the case where the image you are trying to view doesn't exist.

I'm using MVC3, and I know that I can create a custom Image controller action like in https://stackoverflow.com/a/5606575/435460. I'd like a more general solution though.

Upvotes: 2

Views: 250

Answers (2)

Chris Ballance
Chris Ballance

Reputation: 34337

You could write an HTTPModule to intercept requests for common image extensions, test for the presence of the file, and if missing instead return a default image.

Find an overview for writing an HTTPModule here and here

You might also consider a look at this Codeplex project

Upvotes: 1

Squiggs.
Squiggs.

Reputation: 4474

Perhaps an HTTP Handler would be of use here?

Have a look at this article for creative use of HTTPHandlers to prevent file leaching. Pretty sure it could be ammended to serve a default image when it 404's.

http://www.wrox.com/WileyCDA/Section/id-291916.html

Upvotes: 1

Related Questions