Click here to Skip to main content
15,886,026 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

Supporting Development and Release web.config in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
10 Jan 2011CPOL 8.8K   2   3
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...
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.

License

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


Written By
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... Pin
Spectre_00111-Jan-11 1:52
Spectre_00111-Jan-11 1:52 
GeneralThis is new to me. But why do you have to maintain all the o... Pin
Venkatesh Mookkan10-Jan-11 17:10
Venkatesh Mookkan10-Jan-11 17:10 
GeneralRe: At another place I worked, this is the way we did it as well... Pin
KevinAG31-Jan-11 11:40
KevinAG31-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    Praise Praise    Rant Rant    Admin Admin   

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