asp.net - 尝试从 web.config 打开一个部分会出现 ConfigurationErrorsException : The entry KEY has already been added

标签 asp.net web-config configuration-files webconfigurationmanager

我正在尝试从我的 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/

相关文章:

c# - asp .net 核心应用程序未在 IE 和 EDGE 中设置响应 cookie,但在 firefox 和 chrome 中运行良好

asp.net - 如何在 ASP.NET 中实现 PayPal Express Checkout?

url - Http.sys URL 前缀注册如何转换为 IIS 绑定(bind)配置?

ruby-on-rails - Rails 4.0.5 secret.yml 配置

scala - Play Framework 配置包括与 dist 的中断

c# - 如何将原始电子邮件字符串解析为 System.Net.Mail.MailMessage 对象?

c# - ASP.NET Core JWT Bearer Token 自定义验证

asp.net - 加载配置文件时出错 : Failed to map the path '/'

.htaccess - 将 AddType 规则从 htaccess 转换为 web.config

c - webassembly (C) 如何创建配置文件?