Omer
Omer

Reputation: 10174

Custom error page is not displaying on IIS7 ASP.NET

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:

http://localhost:10000/notfound.aspx

It works perfect and redirects to my error page. But when I try below

http://localhost:10000/notfound

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?

enter image description here

Upvotes: 2

Views: 3153

Answers (2)

S-Mun
S-Mun

Reputation: 196

Be sure you've selected "Custom Error Pages" in Error Page settings in IIS.

  1. Login to IIS web server.
  2. Expand the sites and select your website name.
  3. From the Feature view, Under IIS section select the Error Pages.
  4. Select the 404 error and right click on it.
  5. Select the "Edit Feature Settings".
  6. Select "Custom Error Pages" and click OK to save the settings.

enter image description here

Upvotes: 2

T. Frick
T. Frick

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

Related Questions