<customErrors> Element

Provides information about custom error messages for an ASP.NET application.


<customErrors defaultRedirect="url"
   <error statusCode="statuscode"

Required Attribute

Attribute Option Description
Mode     Specifies whether custom errors are enabled, disabled, or shown only to remote clients.
    On Specifies that custom errors are enabled. If no defaultRedirect is specified, users see a generic error.
    Off Specifies that custom errors are disabled. This allows display of detailed errors.
    RemoteOnly Specifies that custom errors are shown only to remote clients and ASP.NET errors are shown to the local host. This is the default.

Optional Attribute

Attribute Description
defaultRedirect Specifies the default URL to direct a browser to if an error occurs. When defaultRedirect is not specified, a generic error is displayed instead. The URL may be absolute (for instance, https://www.contoso.com/ErrorPage.htm) or it may be relative. A relative URL such as /ErrorPage.htm is relative to the Web.config file that specified the defaultRedirect URL, not to the Web page in which the error occurred. A URL starting with a tilde (~),such as ~/ErrorPage.htm, means that the specified URL is relative to the root path of the application.


Subtag Description
<error> The error subtag can appear multiple times. Each appearance defines one custom error condition.


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


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

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


Contained Within: <system.web>

Web Platform: IIS 5.0, IIS 5.1, IIS 6.0

Configuration File: Machine.config, Web.config

Configuration Section Handler: System.Web.Configuration.CustomErrorsConfigHandler

See Also

ASP.NET Configuration | ASP.NET Settings Schema