I keep a single config file and use logic at runtime to detect of which subset of configuration to use. If the hostname is "prodsrvr-*" then I use the production server configuration, including db connections, etc. If the hostname is "test-*" then I use the test config data. And etc.
EDIT: here's some code that does what I described.
public static string GetConnString()
{
string connString = ConfigurationSettings.AppSettings[GetConfigKey("database")];
return connString;
}
public static string GetConfigKey(string baseKey)
{
string str = baseKey;
if (Dns.GetHostName().StartsWith("dinoch"))
{
str = str + "-dev";
}
else if (Dns.GetHostName().StartsWith("prodsrvr"))
{
str = str + "-prod";
}
return str;
}
<configuration>
<appSettings>
<add key="database-dev" value="server=(local)\vsdotnet;database=ASPXAPPS;Integrated Security=SSPI" />
<add key="database-prod" value="server=(local)\vsdotnet;database=ASPXAPPS;Integrated Security=SSPI" />
</appSettings>
</configuration>
I use a simple StartsWith() , with some "magic strings" hardcoded.
To avoid that, I could imagine defining a map of regex's to suffixes in the web.config file. Where, if regex1 is a match on the hostname, then use suffix1. If regex2, then use suffix2. Etc. You would load the map just once, and then just to a foreach() enumerating through the regex's and returning if they match the hostname.
Or, maybe there is a different criterion you want to use, to distinguish prod from dev from test servers, other than hostname. It's up to you.