我正在尝试从我的 ASP.NET 应用程序中的成员(member)提供程序获取一些设置(这样我就不必复制 appSettings 部分中的信息),但出现以下异常:
System.Configuration.ConfigurationErrorsException: The entry 'MyMembershipProvider' has already been added. (C:\Inetpub\intranet-webapp\web.config line 53)
我的代码如下:
var configurationManager = WebConfigurationManager.OpenWebConfiguration("/", "IntranetWebapp");
var section = (MembershipSection) configurationManager.GetSection("system.web/membership");
第二行引发异常。我觉得这很奇怪,因为我没有尝试向配置文件添加任何新信息。相反,我只是想检索它。
我的配置部分的内容:
<membership defaultProvider="IntranetApp">
<providers>
<add applicationName="IntranetApp"
enableSearchMethods="true"
connectionStringName="IntranetConnectionString"
connectionUsername="CN=username,OU=Service Accounts,OU=Users,OU=CompanyName,DC=CompanyName,DC=com"
connectionPassword="********"
name="MyIntranetMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider" />
</providers>
</membership>
非常感谢任何帮助。
巴勃罗
最佳答案
我能够通过执行以下操作解决此问题 CzechDeveloper did ,在相关线程中,其中:
<clear />
重要:只有当我将它直接放在复制的嵌套元素上方时,这才对我有用。
<sso>
<stores>
<clear />
<store name="Store1" apiKey="abcd" />
<store name="Store2" apiKey="efgh" />
</stores>
</sso>
当我们开始添加 virtual directories 时,我们也开始看到这些问题。正如therealsix指出的那样。
关于asp.net - 尝试从 web.config 打开一个部分会出现 ConfigurationErrorsException : The entry KEY has already been added,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1340727/