CustomErrorsSection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
配置 ASP.NET 自訂錯誤。 此類別無法獲得繼承。
public ref class CustomErrorsSection sealed : System::Configuration::ConfigurationSection
public sealed class CustomErrorsSection : System.Configuration.ConfigurationSection
type CustomErrorsSection = class
inherit ConfigurationSection
Public NotInheritable Class CustomErrorsSection
Inherits ConfigurationSection
- 繼承
範例
此範例示範如何宣告式地指定 customErrors 區段中多個屬性的值,這些屬性也可作為類別成員 CustomErrorsSection 存取。
以下設定檔範例說明如何以宣告方式 customErrors 指定該區段的值。
<customErrors mode="RemoteOnly"
defaultRedirect="customerror.htm">
<error statusCode="404" redirect="customerror404.htm"/>
</customErrors>
下列範例將示範如何使用 CustomErrorsSection 類別。
// Get the Web application configuration.
System.Configuration.Configuration configuration =
WebConfigurationManager.OpenWebConfiguration(
"/aspnetTest");
// Get the section.
CustomErrorsSection customErrorsSection =
(CustomErrorsSection)configuration.GetSection(
"system.web/customErrors");
// Get the collection
CustomErrorCollection customErrorsCollection =
customErrorsSection.Errors;
' Get the Web application configuration.
Dim configuration _
As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration( _
"/aspnetTest")
' Get the section.
Dim customErrorsSection _
As CustomErrorsSection = _
CType(configuration.GetSection( _
"system.web/customErrors"), _
CustomErrorsSection)
' Get the collection
Dim customErrorsCollection _
As CustomErrorCollection = customErrorsSection.Errors
備註
這個 CustomErrorsSection 類別提供一種程式化的方式,可以存取並修改設定檔的該 customErrors 區段。 此類型屬於包含 CustomErrorCollection、 CustomErrorsMode、 及 CustomError 類型的群。
Note
可以 CustomErrorsSection 根據該區段屬性 AllowDefinition (值為 Everywhere)從設定檔的相關區段讀寫資訊。
建構函式
| 名稱 | Description |
|---|---|
| CustomErrorsSection() |
使用預設設定初始化該類別的新實例 CustomErrorsSection 。 |