使用web.config覆盖machine.config [英] Override machine.config with web.config

查看:208
本文介绍了使用web.config覆盖machine.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近决定将我的连接字符串移动到machine.config,因为这似乎是迄今为止最优雅的管理多个环境的方法。但是,如果需要,我仍然希望能够覆盖我的本地web.config中的这些设置(或者非开明的群体开始抱怨)。



如何覆盖我的web.config中的machine.config中的设置,而不会得到 ConfigurationErrorsException ,因为该值已经设置?

解决方案

如果您尝试使用与您在machine.config中添加的web.config名称相同的本地web.config添加另一个连接字符串,则需要首先删除它。 connectionStrings元素像字典一样工作,您可以在添加替换字符串之前添加删除或清除标记。有关详情,请参阅。 / p>

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?

解决方案

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.

这篇关于使用web.config覆盖machine.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆