2

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?

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
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.
So, if I have a 404 (on a pdf), IIS is going to take over and redirect to the specified error page in the IIS configuration. Can I remove all of the Error Pages items in the manager and it will use my web.config configuration to determine where to go?
@Keith - good question, it's not something I've tried, but I don't think it will work unless you've also told IIS to use ASP.NET for all requests (i.e. through a wildcard handler for the ASP.NET module) - otherwise it's just not going to associate the request for a .pdf with ASP.NET, and not give it a chance to use the error config.
2

You might be missing mode="On":

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

1 Comment

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! ;)
0

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"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.