Jim Mitchener
Jim Mitchener

Reputation: 9003

Override machine.config with web.config

I have recently decided to move my connection strings to machine.config as this seems to be by far the most elegant approach for managing multiple environments. However, I would still like to be able to override these settings in my local web.config if the need arises (or the non-enlightened masses begin to complain).

How can I override settings from machine.config in my web.config without getting a ConfigurationErrorsException because the value has already been set?

Upvotes: 2

Views: 3882

Answers (1)

Rory
Rory

Reputation: 2742

If you're trying to add another connection string using the local web.config that has the same name as one you've added in machine.config, you will need to remove it first. The connectionStrings element works like a dictionary, you can add a remove or clear tag before adding the replacement string. Take a look at this for details.

Upvotes: 5

Related Questions