CustomErrorsSection Class

Configures ASP.NET custom error messages.

Syntax

class CustomErrorsSection : ConfigurationSectionWithCollection  

Methods

The following table lists the methods exposed by the CustomErrorsSection class.

Name Description
Add (Inherited from ConfigurationSectionWithCollection.)
Clear (Inherited from ConfigurationSectionWithCollection.)
Get (Inherited from ConfigurationSectionWithCollection.)
GetAllowDefinition (Inherited from ConfigurationSection.)
GetAllowLocation (Inherited from ConfigurationSection.)
Remove (Inherited from ConfigurationSectionWithCollection.)
RevertToParent (Inherited from ConfigurationSection.)
SetAllowDefinition (Inherited from ConfigurationSection.)
SetAllowLocation (Inherited from ConfigurationSection.)

Properties

The following table lists the properties exposed by the CustomErrorsSection class.

Name Description
CustomErrors An array of CustomError values that specify ASP.NET custom errors.
DefaultRedirect A required, nonempty read/write string value that contains the default path of either an HTTP error message file or the URL of an error message. This value is inherited by the Redirect property of newly created CustomError objects.
Location (Inherited from ConfigurationSection.) A key property.
Mode A read/write sint32 enumeration that specifies whether custom or default error pages are shown locally or remotely. The possible values are listed later in the Remarks section.
Path (Inherited from ConfigurationSection.) A key property.
SectionInformation (Inherited from ConfigurationSection.)

Subclasses

This class contains no subclasses.

Remarks

The custom errors represented by the CustomErrorsSection class are specific to ASP.NET and are in the <system.web> section of the Web.config file. Each of these errors is represented by an instance of the CustomError class.

The custom errors represented by the HttpErrorsSection class are related to IIS 7 and are in the <system.webServer> section of the ApplicationHost.config file. Each of these errors is represented by an instance of the HttpErrorElement class. The integration of ASP.NET with IIS in IIS 7 made this name change necessary.

The following table lists the possible values for the Mode property. The default is 0 (RemoteOnly).

Value Keyword Description
0 RemoteOnly The default ASP.NET error page is shown to local users. Remote users will receive a custom error page if one is defined. If no custom error page is defined for the error received, an IIS error page is shown.
1 On A user-defined ASP.NET custom error page is shown for both local and remote users.
2 Off The default ASP.NET error page is shown for both local and remote users.

Example

The following example sets the DefaultRedirect property to "CustomError.htm" and the Mode property to On.

' Connect to the WMI WebAdministration namespace.  
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")  
  
' Get the custom errors section for the default Web site.  
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")  
oSite.GetSection "CustomErrorsSection", oSection  
  
' Set the default redirect page to CustomError.htm,  
' and set the Mode property to On.  
oSection.DefaultRedirect = "CustomError.htm"  
oSection.Mode = 1  
oSection.Put_  
  

Inheritance Hierarchy

ConfigurationSection

ConfigurationSectionWithCollection

CustomErrorsSection

Requirements

Type Description
Client - IIS 7.0 on Windows Vista
- IIS 7.5 on Windows 7
- IIS 8.0 on Windows 8
- IIS 10.0 on Windows 10
Server - IIS 7.0 on Windows Server 2008
- IIS 7.5 on Windows Server 2008 R2
- IIS 8.0 on Windows Server 2012
- IIS 8.5 on Windows Server 2012 R2
- IIS 10.0 on Windows Server 2016
Product - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
MOF file WebAdministration.mof

See Also

ConfigurationSectionWithCollection Class
CustomError Class
HttpErrorElement Class
HttpErrorsSection Class