CustomError Class

Specifies an ASP.NET custom error message for an HTTP status code error.

Syntax

class CustomError : CollectionElement  

Methods

This class contains no methods.

Properties

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

Name Description
Redirect A required nonempty read/write string value that contains the path of a file or URL that contains a custom error message.
StatusCode A required unique read/write sint32 value that specifies an HTTP error status code. Valid values are from 100 through 999. The key property.

Subclasses

This class contains no subclasses.

Remarks

Instances of this class are contained in the CustomErrors property of the CustomErrorsSection class.

The custom errors represented by the CustomError class are specific to ASP.NET and are in the <system.web> section of the Web.config file. The custom errors represented by the HttpErrorElement class are specific to IIS 7 and are in the <system.webServer> section of the ApplicationHost.config file.

Example

The following example adds a custom error to the custom errors section of the default Web site.

' Connect to the WMI WebAdministration namespace.  
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")  
  
' Get the CustomError class object.  
Set oCustomError = oWebAdmin.Get("CustomError")  
  
' Create a new instance of the CustomError class.  
Set oNewCustomError = oCustomError.SpawnInstance_  
  
' Assign values to the StatusCode and Redirect properties.  
oNewCustomError.StatusCode = 404  
oNewCustomError.Redirect ="CustomPageNotFoundError.htm"  
  
' Get the custom errors section for the default Web site.   
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")  
oSite.GetSection "CustomErrorsSection", oCustomErrorsSection  
  
' Call the CustomErrorsSection.Add method to add the custom error.  
oCustomErrorsSection.Add "CustomErrors", oNewCustomError  
  

Inheritance Hierarchy

CollectionElement

CustomError

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

CollectionElement Class
CustomErrorsSection Class
HttpErrorElement Class
HttpErrorsSection Class