问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/1982090/override-machine-config-with-web-config