Handling multiple configuration settings (Development, Staging, Production) gracefully.

In Asp.net 2.0 multiple connectionStrings & appSettings can be handled very easily using the attribute “configSource”

create a new xml file devAppSettings.config under a new folder myConfigsettings

<?xml version=”1.0″?>

  <add key=”uploadfolder” value=”C:\test\UploadDocs”/>

  <add key=”domainname” value=”devdomain”/>


create a new xml file devconnectionStrings.config under a folder myConfigsettings

<?xml version=”1.0″?>

  <add name=”nwind” connectionString=”Data Source=(localhost);Initial Catalog=nwind;User Id=sa;Password=sa;”
    providerName=”System.Data.SqlClient” />


now modify web.config

<connectionStrings configSource=”myConfigsettings\devconnectionStrings.config”/>

<appSettings configSource=”myConfigsettings\devAppSettings.config” />
Similarly you can create as many config files for testing, production and change the name in Web.config



Tip: Unlike web.config,  these config files wont kill the session of current users if you accidentally enter a space and save the file.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: