配置部分'system.web / httpModules'已经定义。每个配置文件只能出现一次。请参阅帮助主题 例外

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了配置部分'system.web / httpModules'已经定义。每个配置文件只能出现一次。请参阅帮助主题 例外相关的知识,希望对你有一定的参考价值。

我知道有类似这个问题的问题。我正在研究一个.Net项目,直到昨天工作正常。今天我在配置文件中看到一个错误。

我得到的错误:

'配置部分'system.web / httpModules'已经定义。每个配置文件只能出现一次。有关例外,请参阅帮助主题

以下是我的配置文件:

我不确定哪个HttpModule必须删除:(

<configuration>
    <configSections>
        <sectionGroup name="elmah">
            <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
            <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
            <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
        </sectionGroup>
    </configSections>
    <appSettings>
        <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
        <add key="Internal" value="localhost;localhost2" />
        <add key="External" value="localhost33" />
    </appSettings>
    <system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="50000000" />
            </webServices>
        </scripting>
    </system.web.extensions>
    <connectionStrings></connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
        <!--Fix for placing secure flag on session cookie-->
        <!--<httpCookies requireSSL="true"/>-->
        <!--<roleManager enabled="true" />-->
        <authentication mode="Forms">
            <!--<forms loginUrl="login.aspx" timeout="9880" requireSSL="true" />-->
            <forms loginUrl="login.aspx" timeout="9880" />
        </authentication>
        <authorization>
            <deny users="?" />
        </authorization>
        <membership defaultProvider="ProjectNameProvider">
            <providers>
                <clear />
                <add name="ProjectNameProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=***" connectionStringName="****" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="***" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
            </providers>
        </membership>
        <roleManager enabled="true" defaultProvider="ProjectNameProvider">
            <providers>
                <clear />
                <add name="ProjectNameProvider" connectionStringName="***" applicationName="***" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=***" />
            </providers>
        </roleManager>
        <pages>
            <controls>
                <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
                <!--<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />-->
            </controls>
        </pages>
        <machineKey decryptionKey="AutoGenerate,IsolateApps" validationKey="AutoGenerate,IsolateApps" />
        <httpModules>
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
            <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
        </httpModules>
    </system.web>
    <location path="Login.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
    <!-- FORGOT SECURITY -->
    <location path="Service/General.asmx">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
    <location path="Accounts_Internal/New_Accounts.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
    <location path="Forgot/Forgot.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
    <location path="Forgot/Forgot_Reset.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
    <location path="Forgot/Forgot_Expired.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
    <system.webServer>
        <defaultDocument>
            <files>
                <remove value="Login.aspx" />
                <add value="Login.aspx" />
            </files>
        </defaultDocument>
        <modules>
            <remove name="Elmah.ErrorLog" />
            <remove name="Elmah.ErrorMail" />
            <remove name="Elmah.ErrorFilter" />
            <add name="Elmah.ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
            <add name="Elmah.ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
            <add name="Elmah.ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
            <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
        </modules>
        <!--
        <rewrite><rules><rule name="Add WWW" enabled="true" stopProcessing="true"><match url="^(.*)$" /><conditions><add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" /></conditions><action type="Redirect" url="https://www.{C:0}{PATH_INFO}" redirectType="Permanent" /></rule></rules></rewrite>
    -->
        <httpProtocol>
            <customHeaders>
                <remove name="X-Frame-Options" />
                <add name="X-Frame-Options" value="DENY" />
                <!--<add name="Strict-Transport-Security" value="max-age=31536000"/>-->
            </customHeaders>
        </httpProtocol>
        <validation validateIntegratedModeConfiguration="false" />
    </system.webServer>
    <elmah>
        <errorLog applicationName="***" type="Elmah.SqlErrorLog, Elmah" connectionStringName="SQLErrorConnection" />
        <errorMail />
        <!--
            See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
            more information on remote access and securing ELMAH.
        -->
        <security allowRemoteAccess="false" />
    </elmah>
    <location>
        <system.web>
            <customErrors mode="Off" />
            <httpModules>
                <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
                <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
                <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
            </httpModules>
        </system.web>
    </location>
    <runtime>
        <assemblyBinding
            xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="htmlAgilityPack" publicKeyToken="bd319b19eaf3b43a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-1.8.6.0" newVersion="1.8.6.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
    <location path="elmah.axd" inheritInChildApplications="false">
        <system.web>
            <httpHandlers>
                <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
            </httpHandlers>
            <!-- 
            See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
            more information on using ASP.NET authorization securing ELMAH.

          <authorization><allow roles="admin" /><deny users="*" /></authorization>
          -->
        </system.web>
        <system.webServer>
            <handlers>
                <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
            </handlers>
        </system.webServer>
    </location>
</configuration>
答案

您将两次添加所有ELMAH模块:

<add name="Elmah.ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="Elmah.ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="Elmah.ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />

我已经在这里描述了如何手动安装ELMAH:Configure elmah.io manually。该指南适用于elmah.io(使用ELMAH的商业服务),但该方法与您的代码相同。你需要从我的样本中取代的唯一东西是ELMAH的ErrorLog-element。

以上是关于配置部分'system.web / httpModules'已经定义。每个配置文件只能出现一次。请参阅帮助主题 例外的主要内容,如果未能解决你的问题,请参考以下文章

System.Web.Optimization 是 .Net Framework 4.5 的一部分吗?

引用类型''声明它在'System.Web'中定义,但无法找到它

web.config 的 System.webServer 和 System.web 部分

系统环境存在啥问题么,报错如下:System.Web.Services.Protocols.SoapException: Object of type 'c__

覆盖 express-gateway 配置

Jexus System.MissingMethodException: Method 'System.Web.Hosting.HostingEnvironment.set_IsHosted&