Click here to Skip to main content
15,891,905 members
Articles / Web Development / ASP.NET
Article

One web.config for all developers

Rate me:
Please Sign up or sign in to vote.
2.88/5 (11 votes)
5 Aug 20041 min read 67.1K   17   10
Allows ASP.NET developers and the final production environment to share one web.config file

Image 1

Introduction

Working on a multi-developer ASP.NET project while sharing one web.config can be time consuming. Usually, each developer may have path and other settings specific to their development machine, such as database connection strings, paths, e-mail addresses, etc.

Background

Switching from a ASP 3.0 server-based development environment to a code versioning ASP.NET local-based development environment posed the challenge of all development machines having different settings. It is too time-consuming and tedious to have multiple copies of web.config, which is why we came up with the notion of reading the machine name and loading the appropriate settings from there.

Using the code

One way to determine and load the appropriate web.config setting is by first reading the machine (computer) name (Note: Ensure System.Environment is not locked down in the ISP’s hosting policy). Once the machine name is obtained, it can then be used as a numeric offset that is used in all other web.config variables that would be developer-specific. A good place to read these settings may be in Global.asax’s Session_Start() method.

C#
// Get this machine's name.
thisMachineName = System.Environment.MachineName.ToUpper();

// Get production machine name from web.config.
machineNameSetting = ConfigurationSettings.AppSettings["machine_name_remote"];

// Was the production machine found?
if (thisMachineName == machineNameSetting)
{
    // Load "remote/live/production" settings.
    index = "_remote";
    devMachineFound = true;
}
else
{
    // Load developer settings...
    // (see demo project)
}

Points of Interest

While this code works well, the ability to retrieve the machine name may be locked down by your host's security policy. Please check with them before assuming this code will run.

History

This methodology is used in all of our ASP.NET applications.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGreat for use with a CVS Pin
PaKettle10-Aug-04 4:00
PaKettle10-Aug-04 4:00 
GeneralRe: Great for use with a CVS Pin
Jason Noftall10-Aug-04 4:08
Jason Noftall10-Aug-04 4:08 
PaKettle wrote:
My team and I just started a new project. We set it up by using the project sample as a reference. It works great with our CVS (Vault). We can now all get the latest version and we don't have to change our DB or email settings. I don't understand the confusion on this article, very simple. You add in your machine name, then you add the settings corresponding to that machine index. It is saving us a ton of time.
All the talk about the local host is foolish criticism; the machine name is great as it does not matter if I use local host, domain name, or an IP address. Machine name should always be unique on a network anyway. Works great for our team.
Great article Jason!

PS - Too bad so many are missing the boat on this one.


Thanks... Unsure | :~ Blush | :O
GeneralRe: Great for use with a CVS Pin
Ashley van Gerven30-Aug-04 3:44
Ashley van Gerven30-Aug-04 3:44 
GeneralStandard override possibility for web.config/appSettings Pin
Victor Vogelpoel10-Aug-04 1:53
Victor Vogelpoel10-Aug-04 1:53 
Generalgood, but could be explained a bit better Pin
Ashley van Gerven7-Aug-04 1:20
Ashley van Gerven7-Aug-04 1:20 
GeneralRe: good, but could be explained a bit better Pin
Jason Noftall9-Aug-04 14:27
Jason Noftall9-Aug-04 14:27 
GeneralRe: good, but could be explained a bit better Pin
Ashley van Gerven9-Aug-04 18:12
Ashley van Gerven9-Aug-04 18:12 
GeneralI'm missing something. Pin
soup6-Aug-04 5:13
soup6-Aug-04 5:13 
GeneralRe: I'm missing something. Pin
Ashley van Gerven7-Aug-04 1:24
Ashley van Gerven7-Aug-04 1:24 
GeneralRe: I'm missing something. Pin
Jason Noftall9-Aug-04 14:14
Jason Noftall9-Aug-04 14:14 

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.