CustomError Class [IIS 7 and higher]

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

Requires IIS 7 on Windows Vista.

Server

Requires IIS 7 on Windows Server 2008.

Product

IIS 7

MOF file

WebAdministration.mof

See Also

Reference

CollectionElement Class [IIS 7 and higher]

CustomErrorsSection Class [IIS 7 and higher]

HttpErrorElement Class [IIS 7 and higher]

HttpErrorsSection Class [IIS 7 and higher]