Danny G
Danny G

Reputation: 3789

environmental configurations

What's the best way to modify web.configs (and other XML based configurations)? I'm needing to automatically apply certain settings based off environment.

Upvotes: 0

Views: 102

Answers (3)

Dave Anderson
Dave Anderson

Reputation: 12294

I usually store my environmental configurations in their own folder with individual config files and reference this with the file attribute of the appsettings tag in the main web.config

  /config/dev.config 
          systest.config
          uat.config
          prod.config

  <appsettings file="config/dev.config">

This means we can deploy all our configs and just switch one value to change environments. The only draw back is this breaks some config editors.

Upvotes: 2

Chris Brandsma
Chris Brandsma

Reputation: 11736

You can do this in your build scripts as well. Both Nant and MSBuild have a notion of Xml Peek and Poke.

Generally I'm against the idea of programattically editing the web.config (it will cause your site to reload).

Upvotes: 0

JP Alioto
JP Alioto

Reputation: 45117

If you mean programatically, there are classes that allow you to do so, such as WebConfigurationManager and ConfigurationManager.

Upvotes: 1

Related Questions