Reputation: 10174
I want to add custom error pages to my site. Firstly I have created a test web project, added two test pages, publish it to my local IIS and configured the web.config:
<configuration>
<system.web>
<compilation targetFramework="4.0" />
<customErrors mode="On" defaultRedirect="http://localhost:10000/apperror.aspx">
<error statusCode="404" redirect="http://localhost:10000/404.aspx" />
</customErrors>
</system.web>
I can browse this pages separately but when I try to access a not found page like:
It works perfect and redirects to my error page. But when I try below
IIS is showing his own error page not my custom error pages. I have searched but not found a solution, Could you please help me how can I achieve this?
Upvotes: 2
Views: 3153
Reputation: 196
Be sure you've selected "Custom Error Pages" in Error Page settings in IIS.
Upvotes: 2
Reputation: 136
I always use this approach. First, remove the error handling from system.web, then add this:
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="404" responseMode="ExecuteURL" path="/Errors/NotFound" />
<error statusCode="500" responseMode="ExecuteURL" path="/Errors/InternalError" />
</httpErrors>
</system.webServer>
Upvotes: 2