Click here to Skip to main content
Click here to Skip to main content

One web.config for all developers

, 5 Aug 2004
Rate this:
Please Sign up or sign in to vote.
Allows ASP.NET developers and the final production environment to share one web.config file

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.

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

About the Author

Jason Noftall
Web Developer
Canada Canada
No Biography provided

Comments and Discussions

 
GeneralGreat for use with a CVS PinmemberPaKettle10-Aug-04 4:00 
GeneralRe: Great for use with a CVS PinmemberJason Noftall10-Aug-04 4:08 
GeneralRe: Great for use with a CVS PinmemberAshley van Gerven30-Aug-04 3:44 
GeneralStandard override possibility for web.config/appSettings PinmemberVictor Vogelpoel10-Aug-04 1:53 
Generalgood, but could be explained a bit better PinmemberAshley van Gerven7-Aug-04 1:20 
GeneralRe: good, but could be explained a bit better PinmemberJason Noftall9-Aug-04 14:27 
GeneralRe: good, but could be explained a bit better PinmemberAshley van Gerven9-Aug-04 18:12 
GeneralI'm missing something. Pinmembersoup6-Aug-04 5:13 
GeneralRe: I'm missing something. PinmemberAshley van Gerven7-Aug-04 1:24 
GeneralRe: I'm missing something. PinmemberJason Noftall9-Aug-04 14:14 

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
Web02 | 2.8.140709.1 | Last Updated 6 Aug 2004
Article Copyright 2004 by Jason Noftall
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid