Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Supporting Development and Release web.config in ASP.NET

By , 10 Jan 2011
Rate this:
Please Sign up or sign in to vote.
I wrote a custom ConfigSectionHandler that allows encrypted entries. Then I crafted a config reader that determines, based on the name of the machine where the code is running, which configuration section to read from while decrypting any encrypted entries on the fly.
There is a special config section defining which section to read values from for each machine (including a default entry that is read from if the current machine is not in the list).
This allows me to maintain a single config file with separate configurations for each environment in separate config sections. The application then reads its configuration values from the appropriate section without any intervention from the person deploying.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Web Developer
United States United States
Senior Software Developer US Coast Guard.

Comments and Discussions

GeneralThe point is to allow a single .config file to handle all en... PinmemberSpectre_00111-Jan-11 1:52 
GeneralThis is new to me. But why do you have to maintain all the o... PinmemberVenkatesh Mookkan10-Jan-11 17:10 
GeneralRe: At another place I worked, this is the way we did it as well... PinmemberKevinAG31-Jan-11 11:40 
At another place I worked, this is the way we did it as well. At that job, we had four environments, development, functional test, beta, and production. Each environment typically had two "NCC" servers, two web servers, and a clustered database server. Our suite of applications used things like MSMQ and every custom service had to be redundant and work well with load balancing.
We then had a naming convention that we used for each server in each environment. dev-ncc1, dev-ncc2, dev-web1, dev-web2, ft-ncc1, ft-ncc2, ft-web1, ft-web2, beta-ncc1, etc...
This would allow for us to create appSettings keys like:
<add key="RefreshCacheIntervalSeconds" value="60"/>
<add key="[dev-web*]RefreshCacheIntervalSeconds" value="10"/>
So while developing, the RefreshCacheIntervalSeconds would have a value of 10, but everywhere else, it would have a value of 60.
This would also allow you to take things a step further and have:
<add key="[dev-web1]RefreshCacheIntervalSeconds" value="10"/>
<add key="[dev-web2]RefreshCacheIntervalSeconds" value="20"/>
<add key="[ft-web1]RefreshCacheIntervalSeconds" value="30"/>
<add key="[ft-web2]RefreshCacheIntervalSeconds" value="40"/>
if there was a setting that needed that kind of fine grained control.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140421.2 | Last Updated 10 Jan 2011
Article Copyright 2011 by Spectre_001
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid