In this post, we're gonna explain how to use ASP.NET to configure custom error pages in IIS (Internet Information Server).  If we configure .NET Error Pages at the site level, ASP.NET stores the settings in the site’s web.config file. Since these settings are stored in the web.config file they are portable and can be easily moved to another server with the site’s content.

Step 1

Open Internet Information Services (IIS) Manager.  Select your website. Note: This could also be set at the server level and applied to all sites on the server. DoubleClick on the “.NET Error Pages” icon.

The .NET Error Pages features view will be displayed.

Step 2

Click the “Edit Feature Settings” link to enable this feature. The “Edit Error Page Settings” dialog box will appear.

In order to change the default mode, we must also specify a “Default Page”. This page will be used for all status codes that are  not otherwise defined. In this example, we are using a generic custom error page to trap all other errors. Once you enter the absolute URL for the default error page click OK.  It may be a good idea to use a static HTML page here just in case ASP.NET is not functioning properly.
By default server errors are shown when logged on locally to the IIS server and custom errors will only be used from remote sessions. You will want to change this to “On” if you are logged on locally to the IIS server. Otherwise, it will display detailed server errors, and not our custom error pages.

Step 3

Next we will explicitly define the 404 Error code. To get the browser to throw a 404 error, we pointed it to a file on the test site that does not exist. As you can see in the following image the friendly HTTP 404 error page was shown in IE9. A friendly HTTP 404 Error in IE9:

Step 4

On the .NET Error Pages Actions menu click the Add link.

Step 5

The “Add Custom Error Page” dialog will appear. This is where you define individual error pages per status code. For this example, you will add a custom page for the HTTP 404 Error.

Now that you have turned on the feature and added a custom page for the 404 status code, you can verify it is working. To verify visit a page that does not exist. In this example, you will use http://mysite.com/deletedfile.aspx. You can see in the following image that the custom error page was shown.

Step 6

As mentioned above this can also be managed from the site’s web.config file. Consider the following configuration section from our site’s web.config file.

<configuration>
  <system.web>
    <customErrors defaultRedirect=”http://mysite.com/errors/Error.aspx” mode=”RemoteOnly”>
       <error redirect=”http://mysite.com/errors/404.aspx” statusCode=”404″ />
    </customErrors>
  </system.web>
</configuration>

Everything you set in the GUI can easily be set directly in the web.config. This will also allow you to setup .NET Error Pages, if you are on a shared hosting Plan.

HostForLIFE.eu IIS 8.0 Hosting

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.