Adding custom error pages to a website
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?
<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>
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?
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.