# Sunday, June 15, 2008
« What to do about Continuous Integration ... | Main | Lily Lake near Estes Park, Colorado »

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:

<configuration>

   <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"/>

   </RSS>

</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!

All comments require the approval of the site owner before being displayed.
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview