| 1. |
Create a configuration section in the <configSections> section of web.config
<section name="WhateverSectionNameYouWant" type="BespokeWebConfigSectionHandler"> |
| 2. |
Add an App_Code class called BespokeWebConfigSectionHandler to implement the
appropriate IConfigurationSectionHandler handler for config sections:
|
| 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"> <ComplexOne> <SubItem value="One"> <LeafNode degree="2:1"> </ComplexOne> </UserThing> </WhateverSectionNameYouWant> |
| 4. |
To retrieve your config section XML in code, just use the configuration settings (or latterly, the configuration manager):
|
| 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! | |