ASP. Net. config-configuration element customerrors

Source: Internet
Author: User

The way the ASP. NET configuration file is configured is actually the most clearly written in MSDN. It's a pity that I've never known the power of MSDN before.

First address: http://msdn.microsoft.com/zh-cn/library/dayb112d (v=vs.80). aspx, and then analyze it individually. I hope I can finish this series of things from beginning to end. In order not to let myself give up too early, I decided to learn from the configuration files I used, and then gradually contact those unfamiliar, and less use.

First, customErrors elements
Properties Description

Defaultredirect

Specifies the default URL to which the browser is directed when an error occurs. If this property is not specified, a generic error is displayed.

An optional property.

The URL can be absolute (such as www.contoso.com/ErrorPage.htm) or relative. A relative URL, such as /errorpage.htm, is relative to the Web. config file that specifies a URL for the property, rather than to the webpage where the error occurred. A URL that begins with a character (~), such as ~/errorpage.htm, indicates that the specified URL is relative to the root path of the application.

Mode

Specifies whether custom errors are enabled or disabled, or only custom errors are displayed to remote clients.

The Required property.

Optional values and descriptions:

On specifies that custom errors are enabled. If defaultredirect is not specified, the user will see a generic error.

OFF specifies that custom errors are disabled. This allows a detailed error of the standard to be displayed.

REMOTEONLY Specifies that custom errors are displayed only to remote clients and that an ASP. NET error is displayed to the local host. This is the default value.

The default value is RemoteOnly.

  2. Location

Customererrors, configuration-> system.web //This element is placed under <system.web> under <configuration> node

  3. Child elements

Elements Description

Error

Specifies a custom error page for the given HTTP status code.

An optional element.

The error token can occur more than once. Each occurrence of a child tag defines a custom error condition.

4. Configuration Example:

<Configuration><System.Web><CustomErrorsDefaultredirect= "defaulterror.htm"//When an error occurs, redirect to Defaulterror.htm= "RemoteOnly" >//Display detailed error messages only for Local users <error statuscode Redirect=" 500Er Ror.htm "/> </ Customerrors> </ system.web></< Span style= "color: #800000;" >configuration>         

5. configuration Section Handler

  This configuration node corresponds to the configuration section class in asp:

System.Web.Configuration.CustomErrorsSection

Take a look at the main public properties in the class:

Property Description
Defaultredirect Gets or sets the default URL for redirection.
Elementinformation Gets the Elementinformation object that contains the ConfigurationElement object's non-customizable information and functionality. (inherited from ConfigurationElement.) )
Errors Gets a collection of Customerror objects, which is the following <error> configuration section.
Lockallattributesexcept Gets the collection of properties that are locked. (inherited from ConfigurationElement.) )
Lockallelementsexcept Gets the collection of elements that are locked. (inherited from ConfigurationElement.) )
Lockattributes Gets the collection of properties that are locked. (inherited from ConfigurationElement.) )
Lockelements Gets the collection of elements that are locked. (inherited from ConfigurationElement.) )
Lockitem Gets or sets a value that indicates whether the element is locked. (inherited from ConfigurationElement.) )
Mode Gets or sets the error display mode.
Sectioninformation Gets a Sectioninformation object that contains non-customizable information and functionality for the ConfigurationSection object. (inherited from ConfigurationSection.) )

Here's how to read and set the configuration section in a program like this:

        PublicActionResult Index () {//<customerrors defaultredirect= "defaulterror.htm" mode= "Off" >//<error statuscode= "500.htm" redirect= "/>//</customErrors>//Customerrorssection customerrorssection = configurationmanager.getsection ("System.web/customerrors") as Customerrorssection;//This can also be obtained, but note the way inside the path is customerrorssection CES = (customerrorssection) webconfigurationmanager.openwebconfiguration ("/"). GetSection ("System.web/customerrors"); Response.Write (CES. defaultredirect);//Output defaulterror.htm Customerrorsmode mode =Ces. Mode; Response.Write (mode);//Output OFFCustomerror CE = CES. errors[0];//Gets the first child <error> node under its Response.Write (CE. StatusCode);//Output of Response.Write (CE. Redirect);//Output 500.htmElementinformation eleinfo = CES. Elementinformation;//Element Information Response.Write (Eleinfo.linenumber);//Output 14 is exactly the line number of the Web. config customerrors System.Configuration.Configuration C = CES. Currentconfiguration; //// output False Indicates whether the node is read-only Response.Write (CES. Lockitem); // output False whether the element is locked Response.Write (CES. Redirectmode); // output Responseredirect An enumeration that redirects a user to a custom error page, Whether the requested Url sectioninformation SI = CES. Sectioninformation; Response.Write (SI. Name); // output customErrors  View ();           

ASP. config-config element customerrors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.