Get the configuration information of ConfigSections in the configuration file!

zhaozj2021-02-16  96

There are a lot of effects in Configsections! I don't have much.

The first thing to pay is! The type of configsections is only instantiated once in a process.

1, configuration file web.config

Allow all users->

2, two important classes

Using system.configuration; using system.collection; using system.xml;

Namespace config {private class configuration {private haShtable m_myregionconfig = new hashtable (); public hashtable myregionconfig {raeturn m_myregionconfig;}

} Public static Configuration GetConfig () {return (Configuration) ConfigurationSettings.GetConfig ( "xinyulou");} internal void LoadValuesFromConfigurationXml (XmlNode node) {foreach (XmlNode child in node.ChildNodes) {m_MyRegionConfig.Add (child.Attributes [ "name "] .Value, child.attributes [" value "]. Value);}}

IconfigurationSectionHandler} IconfigurationSectionHandler:

Public Virtual Object Create (Object Parent, Object Context, XMLNode Node) {Configuration Config = New Configuration (); config.loadvaluesfromConfigurationXML (Node); Return Config;

}

3, the example is used in ASPX!

Private Void Page_Load (Object Sender, System.EventArgs E) {response.write (). MyRegionConfig ["Region"]. Tostring ());}

The power of Configsections is very powerful. There are many kinds of usage and app! There is no longer an example here, and if you have any questions, you can contact me. Or in the recovery!

转载请注明原文地址:https://www.9cbs.com/read-11054.html

New Post(0)