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.
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
thisMachineName = System.Environment.MachineName.ToUpper();
machineNameSetting = ConfigurationSettings.AppSettings["machine_name_remote"];
if (thisMachineName == machineNameSetting)
index = "_remote";
devMachineFound = true;
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.
This methodology is used in all of our ASP.NET applications.