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
XML Version = "1.0" encoding = "UTF-8"?>
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!