About the configurationmanager. getsection () method

Source: Internet
Author: User

Method prototype:

public static object GetSection(string sectionName);

Sectionname: Specifies the path and name of the configuration section.

Return result: the specified system. configuration. configurationsection object, or null if this section does not exist.

Note that the getsection method reads the configsections node, which is located on the web. in the config configuration file, it is special and must be placed on the first node. That is to say, there cannot be other types of nodes before it. Configsections subnodes include section and sectiongroup. The latter is the collection node of the former, for example:

<sectionGroup name="urlRewrite">      <section name="rules" type="Web.UI.RuleProviderHandler"/>    </sectionGroup>

You can configure multiple sectiongroups and classify them based on the name attribute. Next we will talk about its role through the configurationmanager. getsection (...) method call. If a class inherits the iconfigurationsectionhandler interface, the create method of this interface will be triggered, so that we can do something. The following is an example of URL rewriting:

Add node:

Based on the configsections node, we use configurationmanager. getsection to read the type of section with name = "urlrewrite", that is, Web. UI. ruleproviderhandler, and convert it to display:

If we have written a class that is ruleproviderhandler. CS (its namespace is exactly the namespace web. UI), we will let this class inherit from iconfigurationsectionhandler.

So,

xxxxxconf = (xxxxx)ConfigurationManager.GetSection("urlRewrite/rules");

The create method is triggered.

using System.Configuration;using System.Xml;namespace Web.UI{    public class RuleProviderHandler : IConfigurationSectionHandler    {        public RuleProviderHandler() { }        public object Create(object parent, object configContext, XmlNode section)        {           //do something        }    }}

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.