通过web.config中覆盖的machine.config [英] Override machine.config by web.config
问题描述
我学会一起工作内置的.NET配置文件提供程序,并具有以下
问题:
I learn to work with the built-in profile provider of .Net, and have the following problem:
我读到了machine.config中的设置可以通过web.config中的设置被覆盖
的.Net的应用。在machine.config文件进行以下设置有关
对我来说:
I read that the machine.config-settings can be overridden by the web.config-settings of a .Net-Application. The following settings in the machine.config-file are relevant for me:
<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为本地改变供应商的名称。
这应该是没有问题的,因为设置将被覆盖。然而,在运行时
该应用程序我得到的错误:
These settings work to set up local profiles. However, when I copy the settings into the web.config of my application and change the machine.config settings, so that they don´t work any more, I get a configuration error. For example, I change the name of the provider in the machine.config to "Local". This should be no problem, because the settings are overridden. However, when running the application I get the error:
条目AspNetSQLProvider已经被添加(我的翻译)
"The entry "AspNetSQLProvider has already been added" (my translation)
推荐答案
添加&LT;清/&GT;
元素的第一个孩子&LT;&是connectionStrings GT;
。这会导致配置系统忽略的machine.config
添加的所有连接字符串和使用所提供的新的问题。您还可以使用&LT;清除方式&gt;
元素删除单个配置项,如果你不想清除整个事情
Add a <clear />
element as the first child of <connectionStrings>
. It'll cause the configuration system to ignore all connection strings added in machine.config
and use the new ones provided. You can also use <remove>
element to remove a single configuration item if you don't want to clear out the whole thing.
<connectionStrings>
<clear />
<add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
同样的想法适用于&LT;供应商方式&gt;
部分以及
这篇关于通过web.config中覆盖的machine.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!