IUnknown
Windows Azure mumblings of IUnknown

Including settings in Web.Config

Friday, January 29, 2010 8:57 PM

 

While exploring configuration files I stumbled upon a few cool things which we could do with these. (Web.Config and App.Config)

 

Including a configuration into another.

 

We can create a separate file for the AppSettings section of the Web.Config and refer it in the <AppSettings> tag.

 

e.g.

<appSettings file= "testAppSettings.config" >

  </appSettings>

 

 

We can also include the connection strings from a separate files into the Configuration file.

<connectionStrings configSource = "WebConnectionString.config" >
  </connectionStrings>
 

 

This will enable us to have multiple configurations for trials and rather than making specific to the web.config everytime and a lot of commented tags, we can just change the filenames and keep the Web.config clean.

 

Default values in configuration settings.

In spite of having separate configuration files we can still choose to have a standard set of values to default to in absence of any referred files.

 

e.g

<appSettings file = "testAppSettings.config" >
    <add key = "UserName" value = "testUser"/>
    <add key = "Password" value = "Abc1234$$" />
</appSettings>
 
 
        <connectionStrings configSource = "WebConnectionString.config">
                <!—Your connection string here -->
        </connectionStrings>
 

 

In this case if the referred configuration files are not available then the values are defaulted to the ones specified in the Web.Config/App.Config



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# Very userful!

I never thought of doing that before, but I can it being extremely useful! In particular, if you were creating a default "template" for a web application or website (where only individual application/connection settings differ) this might save you a great deal of time.

Thanks for sharing! 1/29/2010 10:08 PM | Arthur Kay

Post a comment