共用方式為


CustomError 類別

指定 HTTP 狀態碼錯誤的 ASP.NET 自訂錯誤訊息。

Syntax

class CustomError : CollectionElement  

方法

這個類別不包含方法。

屬性

下表列出 類別所 CustomError 公開的屬性。

名稱 描述
Redirect 必要的無空讀取/寫入 string 值,其中包含包含自訂錯誤訊息的檔案或 URL 路徑。
StatusCode 指定 HTTP 錯誤狀態碼的必要唯一讀取/寫入 sint32 值。 有效值為 100 到 999。 索引鍵屬性。

子類別

這個類別不包含子類別。

備註

這個類別的實例包含在 CustomErrorsCustomErrorsSection 類別的 屬性中。

類別所代表的 CustomError 自訂錯誤專屬於 ASP.NET,而且位於 <system.web> Web.config檔案的 區段中。 HttpErrorElement類別所代表的自訂錯誤是 IIS 7 特有的,而且位於 <system.webServer> ApplicationHost.config檔案的 區段中。

範例

下列範例會將自訂錯誤新增至預設網站的自訂錯誤區段。

' 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

規格需求

類型 描述
Client - Windows Vista 上的 IIS 7.0
- Windows 7 上的 IIS 7.5
- Windows 8 上的 IIS 8.0
- Windows 10上的 IIS 10.0
伺服器 - Windows Server 2008 上的 IIS 7.0
- Windows Server 2008 R2 上的 IIS 7.5
- Windows Server 2012 上的 IIS 8.0
- Windows Server 2012 R2 上的 IIS 8.5
- Windows Server 2016上的 IIS 10.0
產品 - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
MOF 檔案 WebAdministration.mof

另請參閱

CollectionElement 類別
CustomErrorsSection 類別
HttpErrorElement 類別
HttpErrorsSection 類別