Spencer Ruport
Spencer Ruport

Reputation: 35117

ASP.Net Swallowing 404 Error

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>

Upvotes: 3

Views: 622

Answers (1)

joelt
joelt

Reputation: 2680

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.

Upvotes: 1

Related Questions