Reputation: 3789
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
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
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
Reputation: 45117
If you mean programatically, there are classes that allow you to do so, such as WebConfigurationManager and ConfigurationManager.
Upvotes: 1