CustomError 类

指定 HTTP 状态代码错误的 ASP.NET 自定义错误消息。

语法

class CustomError : CollectionElement  

方法

此类不包含任何方法。

属性

下表列出了 CustomError 类公开的属性。

名称 描述
Redirect 一个必需的非空读/写 string 值,该值包含含自定义错误消息的文件或 URL 的路径。
StatusCode 一个必需的唯一读/写 sint32 值,该值指定 HTTP 错误状态代码。 有效值介于 100 和 999 之间。 键属性。

子类

此类不包含子类。

注解

此类的实例包含在 CustomErrorsSection 类的 CustomErrors 属性中。

CustomError 类表示的自定义错误特定于 ASP.NET,且位于 Web.config 文件的 <system.web> 部分。 HttpErrorElement 类表示的自定义错误特定于 IIS 7,且位于 ApplicationHost.config 文件的 <system.webServer> 部分。

示例

以下示例将自定义错误添加到默认网站的自定义错误部分。

' 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  
  

继承层次结构

CollectionElement

CustomError

要求

类型 描述
客户端 - IIS 7.0(在 Windows Vista 上)
- IIS 7.5(在 Windows 7 上)
- IIS 8.0(在 Windows 8 上)
- IIS 10.0(在 Windows 10 上)
服务器 - IIS 7.0(在 Windows Server 2008 上)
- IIS 7.5(在 Windows Server 2008 R2 上)
- IIS 8.0(在 Windows Server 2012 上)
- IIS 8.5(在 Windows Server 2012 R2 上)
- IIS 10.0(在 Windows Server 2016 上)
产品 - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
MOF 文件 WebAdministration.mof

另请参阅

CollectionElement 类
CustomErrorsSection 类
HttpErrorElement 类
HttpErrorsSection 类