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

我学习使用.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>部分以及。

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....