Eric's Blog

Day to day experience in .NET
Welcome to Blogs @ IRM Sign in | Join | Help
 Search

Disclaimer

The content of this site is my own personal opinion and does not in any way represent my employer, it's subsideries or affiliates. These postings are provided "AS IS" with no warranties, and confer no rights.

This Blog

The Small Things: configSource Attribute

Back in 1.0 and 1.1 of .NET Framework there was support for having the appSettings configuration in an external file by specifying the file attribute. This was a great feature during development, because it allows each developer to have it's own configuration, for example each developer could control which database (server or local) they would like to access (if you used appSettings for such configuration). Enterprise Library added support for splitting big complex configuration files in several smaller. On advantage/disadvantage was that these external files was not monitored for change, which meant that changes in them during runtime would not be picked up by ASP.Net.
In 2.0 of the framework it is very easy to create "real" configuration settings through the project properties dialog, that also brings strongly typed access to the settings. This means that the appSettings are not used so much anymore. Still it would be very useful to be able to have some configuration in an external file.
Each configuration section are now able to have it's content in an external file, by setting the configSource attribute. One difference is that, when this attribute is set, you are not allowed to have any other content in the section at all. This is because configuration merging is not supported. The drawback of the fact that configuration merging is not supported is that it's not possible to have default configuration, if the external file is not available, which we used with the file attribute of the appSettings section.
Here is an example of configSource attribute:
 
web.config
<?xml version="1.0"?>

<
configuration
>
  <
connectionStrings configSource="connectionStrings.config"
/>
</
configuration>
 
connectionStrings.config
<?xml version="1.0"?>

<
connectionStrings
>
  <
add name="Northwind" connectionString="Server=(local);Initial Catalog=Northwind;Integrated Security=SSPI;"
/>
</connectionStrings>
 
By the way, this is my 100 post! :-)
Published den 27 maj 2006 08:40 by ericqu

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server, by Telligent Systems