0

I have a web page which renders images from a server. If the image is not found, currently the IIS server returns 404 error and hence the image is not rendered.

I have a requirement to put a default image in case the image is not found on the server.

Can I make this setting on the IIS server so that it returns the default image for every invalid image requests?

2 Answers2

1

You can use the javascript onerror() event for images that are not found:

function imgError(image) {
        image.onerror = "";
        image.src = "somePlaceholderImage.gif";
        return true;
 }

then your images would be like this:

<img alt="some ALT text" src="http://someurlhere" onerror="imgError(this);">
JanR
  • 6,052
  • 3
  • 23
  • 30
0
   <rewrite>
            <rules>
                <rule name="RewriteNoneExist">
                    <match url="\.(gif|jpe?g|png|bmp)"  ignoreCase="true" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="gfx/default.png" />
                </rule>
            </rules>
        </rewrite>
Miguel
  • 3,349
  • 2
  • 32
  • 28