CustomError クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ASP.NET エラー コードをカスタム ページにマップするように、CustomError セクションを構成します。 このクラスは継承できません。
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 エラーを発行します。
コンストラクター
| 名前 | 説明 |
|---|---|
| CustomError(Int32, String) |
CustomError クラスの新しいインスタンスを初期化します。 |