加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 通过web.config覆盖machine.config

发布时间:2020-12-16 00:22:49 所属栏目:asp.Net 来源:网络整理
导读:我学习使用.Net的内置配置文件提供程序,并具有以下功能 问题: 我读到machine.config-settings可以被web.config设置覆盖 的一个.Net应用程序。 machine.config-file中的以下设置是相关的 为了我: connectionStringsadd name="LocalSqlServer" connectionSt
我学习使用.Net的内置配置文件提供程序,并具有以下功能
问题:

我读到machine.config-settings可以被web.config设置覆盖
的一个.Net应用程序。 machine.config-file中的以下设置是相关的
为了我:

<connectionStrings>
<add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;
Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

<profile><providers><add name="AspNetSqlProfileProvider"connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/></providers></profile>

这些设置用于设置本地配置文件。
但是,当我将设置复制到我的应用程序的web.config中并更改
machine.config设置,使他们不再工作,我得到一个配置
错误。
例如,我将machine.config中的提供程序的名称更改为“Local”。
这应该没有问题,因为设置被覆盖。但是,运行时
应用程序我得到错误:

“入门”AspNetSQLProvider已经添加“(我的翻译)

解决方法

添加< clear />元素作为< connectionStrings>的第一个子元素。这将导致配置系统忽略在machine.config中添加的所有连接字符串,并使用提供的新连接字符串。您也可以使用< remove>元素,以删除单个配置项,如果你不想清除整个事情。
<connectionStrings>
   <clear />
   <add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/> 
</connectionStrings>

同样的想法适用于< providers>部分以及。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读