System.Web.Configuration Namespace
.NET Framework version 2.0
Configures custom error handling for a Web application. This class cannot be inherited.
The CustomErrorsSection class provides a way to programmatically access and modify the customErrors section of a configuration file.
This type is part of a group that includes the CustomError, CustomErrorCollection, and CustomErrorsMode types.
NOTE: The CustomErrorsSection can read and write information from and to the related section of the configuration file according to the section property AllowDefinition whose value is Everywhere.
This example demonstrates how to specify values declaratively for several attributes of the customErrors section, which can also be accessed as members of the CustomErrorsSection class.
The following configuration file example shows how to specify values declaratively for the customErrors section.
<customErrors mode = "RemoteOnly"
defaultRedirect = "customerror.htm">
<error statusCode = "404" redirect = "customerror404.htm" />
</customErrors>
The following code example demonstrates how to use the CustomErrorsSection class.
// 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 |
|
C# |
VB |
ASP.NET Configuration <customErrors> Section CustomErrorsMode Enumeration