3

So I've set up a rule in IIS7 to redirect to a specific page on a 404 error.

This works great as long as I'm typing URLs such as:

www.abc.com/Test/

However as soon as I attempt to access a file that doesn't exist

www.abc.com/Test/Test.aspx

I get the ASP.Net error message:

Server Error in '/' Application.

The resource cannot be found.

How can I keep ASP.Net from swallowing the 404 error and overriding my settings in IIS7?

EDIT: Here's my web.config file. IIS added the system.webServer stuff not me.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
    <system.webServer>
        <httpErrors>
            <remove statusCode="403" subStatusCode="-1" />
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/redir.aspx" responseMode="ExecuteURL" />
            <error statusCode="403" prefixLanguageFilePath="" path="/redir.aspx" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>
3
  • have you changed the web.config error section to point to the same page? Commented Mar 15, 2011 at 3:51
  • You are probably better off doing the reverse and having ASP.Net handle all of your 404 errors. Commented Mar 15, 2011 at 4:21
  • As far as I understand it, ASP.Net can't catch 403 errors so unless someone can show me otherwise that isn't an option either. Commented Mar 15, 2011 at 4:47

1 Answer 1

1

If you're in Classic pipeline mode, you may be able to use the "Invoke handler only if request is mapped to file" option. I had to turn it on for two .aspx mappings--I think one was 32 bit and one was 64.

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

1 Comment

Ah, I figureed I'd have to do something hacky like that. Ugh.

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.