January 13, 2011

Well Sometimes You Need Configuration

This post describes how to use configSource in .Net to split up config file settings for developers. This allows us to have standard common config settings in the main web.config or app.config and then have developer specific values in another file.

This example shows how a developer can set up their own connection strings in a seperate config file that won't affect other developers:

In the main web.config file replace your regular connectionStrings section with the following:


Create a file at the same level in the project as the Web.config file and call it Web.LocalDeveloper.config (or any other standard name your team wishes to use).
In the new Web.LocalDeveloper.config enter your specific settings for your local developer workstation:


   


Note: The best practice is to make sure to use .config as the extension of your files so they cannot be served to the browser. Avoid .xml for example or your files can be available to prying eyes.

Next in our config transform files we can add Xpath expressions to remove the "configSource" entry and add the appropriate configuration entries based on the environment.

In the following example we remove the configSource and add the DBConnection connection string:


    

No comments:

Post a Comment

Your feedback is appreciated!