CustomError 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
配置一個 CustomError 區段,將 ASP.NET 錯誤代碼對應到自訂頁面。 此類別無法獲得繼承。
public ref class CustomError sealed : System::Configuration::ConfigurationElement
public sealed class CustomError : System.Configuration.ConfigurationElement
type CustomError = class
inherit ConfigurationElement
Public NotInheritable Class CustomError
Inherits ConfigurationElement
- 繼承
範例
此範例示範如何宣告性地指定多個區段屬性的值,這些屬性 customErrors 也可作為類別成員 CustomError 存取。
以下設定檔範例說明如何以宣告方式 customErrors 指定該區段的值。
<customErrors mode="RemoteOnly"
defaultRedirect="customerror.htm">
<error statusCode="404" redirect="customerror404.htm"/>
</customErrors>
以下程式碼範例示範如何使用這個 CustomError 類別。
// Get the Web application configuration.
Configuration configuration =
WebConfigurationManager.OpenWebConfiguration(
"/aspnetTest");
// Get the section.
CustomErrorsSection customErrors =
(CustomErrorsSection)configuration.GetSection(
"system.web/customErrors");
// Get the collection.
CustomErrorCollection customErrorsCollection =
customErrors.Errors;
' Get the Web application configuration.
Dim configuration _
As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration( _
"/aspnetTest")
' Get the section.
Dim customErrors As CustomErrorsSection = _
CType(configuration.GetSection( _
"system.web/customErrors"), CustomErrorsSection)
' Get the collection.
Dim customErrorsCollection _
As CustomErrorCollection = _
customErrors.Errors
備註
這個 CustomError 類別提供一種程式化的方式,可以存取並修改設定檔的該 error 區段。 此類型屬於包含 CustomErrorCollection、 CustomErrorsMode、 CustomErrorsSection和 的群。
Note
當你定義自訂錯誤時,ASP.NET 會指派底層服務通常發出的標準錯誤,例如 IIS。 例如,如果你為狀態碼 404 定義自訂錯誤,ASP.NET 只要你引用不存在的 .aspx 頁面就會發出錯誤。 自訂錯誤僅針對 ASP.NET 處理的元素發出。 例如,如果你提到不存在的 .htm 頁面,IIS 會發出標準的 404 錯誤。
建構函式
| 名稱 | Description |
|---|---|
| CustomError(Int32, String) |
初始化 CustomError 類別的新執行個體。 |