error Element for customErrors (ASP.NET Settings Schema)

Specifies the custom error page for a given HTTP status code.

<error statusCode="statuscode"
       redirect="url"/>

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Description

statusCode

Required attribute.

Specifies the HTTP status code that results in redirection to the error page.

redirect

Required attribute.

The URL of the custom page that is mapped to the error code.

Child Elements

None.

Parent Elements

Element Description

configuration

Specifies the required root element in every configuration file that is used by the common language runtime and the .NET Framework applications.

system.web

Specifies the root element for the ASP.NET configuration section.

customErrors

Provides information about custom error messages for an ASP.NET application. It can be defined at any level in the application file hierarchy.

Example

The following configuration code example specifies the error handling pages to use for an ASP.NET application.

The custom errors are only issued for the elements that are handled by ASP.NET. For example, if you refer to a non-existing .htm page, Microsoft Internet Information Services (IIS) issues the standard 404 error. If you refer instead to a non-existing .aspx page, ASP.NET issues the custom 404 error, if you configured the error.

<configuration>
  <system.web>
    <customErrors defaultRedirect="GenericError.htm"
                  mode="RemoteOnly">
       <error statusCode="500"
              redirect="InternalError.htm"/>
    </customErrors>
  </system.web>
</configuration>

Element Information

Configuration section handler

System.Web.Configuration.CustomErrorsSection

Configuration member

System.Web.Configuration.CustomErrorsMode

Configurable locations

Machine.config

Root-level Web.config

Application-level Web.config

Virtual or physical directory–level Web.config

Requirements

Microsoft Internet Information Services (IIS) version 5.0, 5.1, or 6.0

The .NET Framework version 1.0, 1.1, or 2.0

Microsoft Visual Studio 2003 or Visual Studio 2005

See Also

Tasks

How to: Lock ASP.NET Configuration Settings

Reference

customErrors Element (ASP.NET Settings Schema)
system.web Element (ASP.NET Settings Schema)
configuration Element (General Settings Schema)
System.Configuration
System.Web.Configuration

Concepts

ASP.NET Configuration Overview
ASP.NET Web Server Controls and Browser Capabilities
Securing ASP.NET Configuration
ASP.NET Configuration Scenarios

Other Resources

ASP.NET Configuration Files
ASP.NET Configuration Settings
General Configuration Settings (ASP.NET)
ASP.NET Configuration API