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 } }}