Fabrice's weblog

Tools and Source

News


Read sample chapters or buy LINQ in Action now!
Our LINQ book is also available on AMAZON

.NET jobs

Emplois .NET

The views expressed on this weblog are mine alone and do not necessarily reflect the views of my employer. The content of this weblog is independent from Microsoft or any other company. transatlantys hot news

Contact

Me

Others

Selected content

Using configSource to split configuration files

As Nikhil Kothari writes in his blog, he's started to use the configSource attribute to split configuration files into smaller pieces.

For example, here is how he exports the profile configuration into a dedicated configuration file.
This is web.config:

...
  <system.web>
    ...
    <profile configSource="profile.config" />
    ...
  </system.web>
...

This is profile.config:

<profile>
  <properties>
    <add name="Name" type="String" />
    <add name="Age" type="Int32" />
  </properties>
</profile>
 

Make sure you 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.

I've been using this feature for my web sites for a while. This allows having a unique web.config file, and separate sub-files for things that are different between the development machine and the hosting environment. For example, I have different connectionStrings.config and smtp.config files for the two environments. The benefits: the web.config file is smaller and hence easier to read, and you don't need a complete web.config file for each environment.

Comments

lkempe said:

Fabrice you might also use Visual Studio 2005 Web Deployment Projects to manage build configurations that are stage dependant. I am using it on Tech Head Brothers website for example.

# April 26, 2007 4:14 AM

Chris D said:

Now if only you could point configSource at a parent directory it might be useful.  Quite ridiculous that it doesn't support absolute paths or at least ..\ notation...

# April 26, 2007 9:40 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)