Web Deployment Projects and deploying web.config settings for multiple machines

I wrote the following comment on a post http://weblogs.asp.net/dfindley/archive/2006/06/06/Frustrations-with-Web-Deployment-Projects.aspx about having machine dependent configurations in your web.config. DFindley expresses some frustrations with the web deployment projects on configuring per machine settings in the web.config, but he found the fix right away. This approach is powerful, but sometimes not clear where the settings are actually managed. I use another approach that works quite well for me. I posted this as a comment on the mentioned post.

Scott mentions in his comment to have a web.config per machine, and copy the correct web.config on deployment.
I prefer to only have replacements for the changing sections per machine. Often these settings are the appSettings, connections and an impersonation account.
In this approach you can manage the other settings in a generic web.config that is used for all machines.
So what I do is the following:

Create appSettings files per machine:


Create connections files per machine:


On automated deployment check your machine name, and copy:

MACHINEX.appSettings.config to appSettings.config
MACHINEX.connections.config to connections.config

In your web.config you refer to those external files as follows:

<appSettings configSource="appSettings.Config"/>
<connectionStrings configSource="connections.config"/>

Another thing you often want to set is the impersonation account, we manage those in the registry per server in a secure way as follows:

<!-- Impersonation identity is encrypted in the registry. Identity is set with the following command:
aspnet_setreg.exe -k:SOFTWARE\MyApp\identity -u:"yourdomainname\username" -p:"password"
Tool can be downloaded at:
<identity impersonate="true"
          password="registry:HKLM\SOFTWARE\MyApp\identity\ASPNET_SETREG,password" />


Comments have been disabled for this content.