How do you display custom error pages on an ASP.Net application?

How can you create custom error pages on an ASP.Net application so that you can better control the user experience when the unexpected happens?

A:

There is a configuration parameter in the Web.Config you can use to control what error pages the user sees:

<customErrors defaultRedirect=”ErrorPage.aspx” mode=”On”>

<error statusCode=”500″ redirect=”servererror.aspx” />

<error statusCode=”404″ redirect=”filenotfound.aspx” />

<error statusCode=”403″ redirect=”AccessDenied.aspx” />

</customErrors>

This section of the web.config has to be placed in the following structure:
<configuration> Element
  system.web Element (ASP.NET Settings Schema)
    <customErrors>
You can obtain more information on how to set this up by visiting the MSDN website. Here is an example obtained from there:

<configuration>

<system.web>

<customErrors defaultRedirect=”GenericError.htm”

mode=”RemoteOnly”>

<error statusCode=”500″

redirect=”InternalError.htm”/>

</customErrors>

</system.web>

</configuration>

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.