views:

22

answers:

2

I have a website that makes use of a web.config. I tried adding in the following code:

<customErrors mode="On" defaultRedirect="error.htm">
            <error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>

But it doesn't seem to work. Errors still show up. Could I be putting it in the wrong place?

Sample:

<authentication mode="Forms">
      <!-- Assign login url to LOGINSTATUS control -->
            <!-- log user out after 15 minutes of inactivity -->
            <forms loginUrl="~/Tilton/Login/Login.aspx" timeout="15"/>
        </authentication>
    <customErrors mode="On" defaultRedirect="error.htm">
      <error statusCode="404" redirect="FileNotFound.htm" />
    </customErrors>
+2  A: 

The ASP.NET error handler only works for resources that would have been handled by the ASP.NET engine should they exist. Example, your handler should work for nonexist.aspx, but won't work for foo.bar because .bar is not mapped to ASP.NET. Is this your problem?

x0n
After some tests I can see what you mean, yes. Anything related to page.aspx works yet page.page won't.
BioXhazard
Is there something I could do so it handles everything?
BioXhazard
The custom error page within IIS is what you want, not the ASP.NET one. If you go into the ASP.NET ISAPI handler in IIS configuration and tell it to "check file exists" then all missing files will go to IIS's handler, including ones that would normally be handled by ASP.NET. If you don't want to check that box, you'll need two 404 handlers - one in IIS, the other in web.config.
x0n
btw, there's nothing you can do to force ASP.NET to handle all (in iis6, not so sure about iis 7).
x0n
A: 

You could look at setting a custom 404 error page within IIS itself. In IIS 7 there's a 'error pages' configuration section for each website.

James O'Sullivan