views:

504

answers:

3

I have custom errors configured in my web.config, but IIS 6.0 is returning the custom error specified in the Custom Errors tab of the website configuration.

  <system.web>
        <customErrors>
              <error statusCode="404" redirect="UrlRedirect.aspx" />
        </customErrors>
  </system.web>

What can I be missing?

+2  A: 

You might be missing mode="On":

<system.web>
        <customErrors mode="On">
              <error statusCode="404" redirect="UrlRedirect.aspx" />
        </customErrors>
</system.web>
Phaedrus
Yes, I am... silly me. Although, I finally got it to work in IIS by pointing the custom errors to a URL... and I don't want to change it now! ;)
Jason
A: 

Actually, if I'm understanding your dilemma correctly, it sounds like the custom error IS being returned, if this is not what you want you will need to turn the mode to "Off" or "RemoteOnly" in order to see detailed error messages in your environment.

<customErrors mode="Off"/>
Ryan Eastabrook
+1  A: 

Bear in mind that the 404 handler specified in the web.config only kicks in for files handled by the ASP.NET runtime - .htm, images, css, javascript will all be handled by the 404 page specified in your hosts IIS settings.

If you want these file types to be handled by your custom error, you'll need to set IIS to direct 404's to UrlRedirect.aspx.

Zhaph - Ben Duguid
Yes, this is what I ultimately did... but how can I get it to be handled in Web.Config? This is what all the examples online show (i.e. 404 error) but they did not work for me.
Jason
You can't, unless you tell IIS to direct all requests via the ASP.NET handler, which has performance implications. Defining the redirect in both places is the only real way to handle all 404s.
Zhaph - Ben Duguid