How to have your own config section in web.config

1. Create a configuration section in the <configSections> section of web.config

<section name="WhateverSectionNameYouWant" type="BespokeWebConfigSectionHandler">
NOTE FOR .NET v4 onwards
You may need to put the Assembly name (Project name usually, unless you changed it) after the type, e.g.
<section name="WhateverSectionNameYouWant" type="Namespace.BespokeWebConfigSectionHandler, AssemblyName">
2. Add an App_Code class called BespokeWebConfigSectionHandler to implement the appropriate IConfigurationSectionHandler handler for config sections:

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.XPath;

public class BespokeWebConfigSectionHandler : IConfigurationSectionHandler
    public object Create(object parent, object configContext, System.Xml.XmlNode section)
        XPathNavigator nav = section.CreateNavigator();
        return nav.InnerXml;   // or .OuterXml if you need the container
3. Now add your named XML configuration section to anywhere in web.config:

<WhateverSectionNameYouWant type="string">
  <UserThing value="foobar" param="All Your Base">
    <Another key="21">
      <SubItem value="One">
      <LeafNode degree="2:1">
4. To retrieve your config section XML in code, just use the configuration settings (or latterly, the configuration manager):

string MySectionXMLstring = ConfigurationSettings.GetConfig("WhateverSectionNameYouWant").ToString();
NOTE FOR .NET v4 onwards
ConfigurationSettings is deprecated, so use ConfigurationManager.GetSection instead
string MySectionXMLstring = ConfigurationManager.GetSection("WhateverSectionNameYouWant").ToString();
5. You can make the handler do more specific things with the XML, rather than just return it to the calling code (such as set Application variables) and you could also make it return an XmlDocument type instead of a string. The options are endless.

And that is all there is! You can put whatever XML configuration data you like in the web.config!