With as many new modules as I've created for my web sites and shared between them all, I've developed a need for custom sections in my web configs. That way it's easy to copy and paste setting for a component into a new (or existing) project and not worry about overlapping (i.e to config elements with the same name). I've been doing this for a long time but it always took me 4 or 5 lines of code to access the values in the elements.
Here some example web.config code:
<
<configSections>
<section name="RSS" type="System.Configuration.DictionarySectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<RSS>
<add key="ContentType" value="text/xml"/>
<add key="Title" value="Site Construx's Article RSS Feed"/>
</
</configuration>
Here's how to access the custom config element with a single line of code
(string)((Hashtable)ConfigurationManager.GetSection("RSS"))["Generator"];
If you're having trouble with this feel free to post a comment and I'll help you out!
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.2.8279.16125
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, Michael Reynolds
E-mail