Share via

customErrors Element (ASP.NET Settings Schema)

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

<customErrors defaultRedirect="url"
     <error. . ./>

Attributes and Elements

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


Attribute Description


Optional attribute.

Specifies the default URL to direct a browser to, if an error occurs. When this attribute is not specified, a generic error is displayed instead.

The URL can be absolute (for example, or relative. A relative URL, such as /ErrorPage.htm, is relative to the Web.config file that specified the URL for this attribute, not to the Web page in which the error occurred. A URL starting with a tilde (~), such as ~/ErrorPage.htm, indicates that the specified URL is relative to the root path of the application.


Required attribute.

Specifies whether custom errors are enabled, disabled, or shown only to remote clients.

This attribute can be one of the following values.

Value Description


Specifies that custom errors are enabled. If no defaultRedirect attribute is specified, users see a generic error. The custom errors are shown to the remote clients and to the local host.


Specifies that custom errors are disabled. The detailed ASP.NET errors are shown to the remote clients and to the local host.


Specifies that custom errors are shown only to the remote clients, and that ASP.NET errors are shown to the local host. This is the default value.

The default is RemoteOnly.

Child Elements

Element Description


Optional element.

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

The error tag can appear multiple times. Each appearance defines one custom error condition.

Parent Elements

Element Description


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


Specifies the root element for the ASP.NET configuration settings in a configuration file and contains configuration elements that configure ASP.NET Web applications and control how the applications behave.


The <customErrors> element does not apply to errors that occur in XML Web services.

Default Configuration

The following default customErrors element is configured in the Machine.config file in the .NET Framework versions 1.0 and 1.1.

<customErrors mode="RemoteOnly" />


The following configuration example demonstrates how to specify the error handling pages to use for an ASP.NET application.

    <customErrors defaultRedirect="GenericError.htm"
      <error statusCode="500"

Element Information

Configuration section handler


Configuration member



Configurable locations


Root-level Web.config

Application-level Web.config

Virtual or physical directory–level Web.config


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


How to: Lock ASP.NET Configuration Settings


system.web Element (ASP.NET Settings Schema)
configuration Element (General Settings Schema)
error Element for customErrors (ASP.NET Settings Schema)


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