EASY, EASY custom web.config section – level 200

Some people my shy away from this, but see how easy it is.  You need a block of custom xml as configuration, so you create your own .xml file and read it in.  Instead, use the web.config file.  It’s already there, and it’s good to keep all configuration in one place.  This is all it takes to make your own Configuration Handler class:


public class Config : IConfigurationSectionHandler {


//stores authorization xml from .config file


protected static XmlNode m_oXmlSection;


public static XmlNode XmlSection{


get { return m_oXmlSection; }


}


public object Create(object parent, object configContext, XmlNode section) {


m_oXmlSection = section.FirstChild;


return section.InnerXml;


}


}


Then, you just access Config.XmlSection, and you have the complete Xml, so why wouldn’t you do it this way?