設定 ASP.NET 自訂錯誤訊息。
Syntax
class CustomErrorsSection : ConfigurationSectionWithCollection
方法
下表列出 類別所 CustomErrorsSection 公開的方法。
| 名稱 | 描述 |
|---|---|
| 加入 | (繼承自 ConfigurationSectionWithCollection.) |
| 清除 | (繼承自 ConfigurationSectionWithCollection。) |
| Get | (繼承自 ConfigurationSectionWithCollection。) |
| GetAllowDefinition | (繼承自 ConfigurationSection.) |
| GetAllowLocation | (繼承自 ConfigurationSection。) |
| 移除 | (繼承自 ConfigurationSectionWithCollection。) |
| RevertToParent | (繼承自 ConfigurationSection。) |
| SetAllowDefinition | (繼承自 ConfigurationSection。) |
| SetAllowLocation | (繼承自 ConfigurationSection。) |
屬性
下表列出 類別所 CustomErrorsSection 公開的屬性。
| 名稱 | 描述 |
|---|---|
CustomErrors |
CustomError值的陣列,指定 ASP.NET 自訂錯誤。 |
DefaultRedirect |
必要、無空的讀取/寫入 string 值,其中包含 HTTP 錯誤訊息檔案的預設路徑或錯誤訊息的 URL。 這個值是由 Redirect 新建立 的 CustomError 物件的 屬性所繼承。 |
Location |
(繼承自 ConfigurationSection .) 金鑰屬性。 |
Mode |
讀取/寫入 sint32 列舉,指定在本機或遠端顯示自訂或預設錯誤頁面。 後續的一節會列出可能的值。 |
Path |
(繼承自 ConfigurationSection .) 金鑰屬性。 |
SectionInformation |
(繼承自 ConfigurationSection。) |
子類別
這個類別不包含子類別。
備註
類別所 CustomErrorsSection 代表的自訂錯誤專屬於 ASP.NET,而且位於 <system.web> Web.config檔案的 區段中。 每個錯誤都是以 CustomError 類別的實例來表示。
HttpErrorsSection類別所代表的自訂錯誤與 IIS 7 相關,且位於 <system.webServer> ApplicationHost.config檔案的 區段中。 每個錯誤都是以 HttpErrorElement 類別的實例來表示。 在 IIS 7 中與 IIS 整合 ASP.NET,因此需要變更此名稱。
下表列出 屬性的 Mode 可能值。 預設值為 0 (RemoteOnly) 。
| 值 | 關鍵字 | 描述 |
|---|---|---|
| 0 | RemoteOnly |
預設 ASP.NET 錯誤頁面會顯示給本機使用者。 如果已定義遠端使用者,則遠端使用者會收到自訂錯誤頁面。 如果未針對收到的錯誤定義任何自訂錯誤頁面,則會顯示 IIS 錯誤頁面。 |
| 1 | On |
本機和遠端使用者都會顯示使用者定義的 ASP.NET 自訂錯誤頁面。 |
| 2 | Off |
本機和遠端使用者都會顯示預設 ASP.NET 錯誤頁面。 |
範例
下列範例會將 DefaultRedirect 屬性設定為 「CustomError.htm」,並將 Mode 屬性設定為 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_
繼承階層架構
ConfigurationSectionWithCollection
CustomErrorsSection
規格需求
| 類型 | 描述 |
|---|---|
| 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 |
另請參閱
ConfigurationSectionWithCollection 類別
CustomError 類別
HttpErrorElement 類別
HttpErrorsSection 類別