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

Config section 'system.web/httpModules' already defined. Sections must only appear once per config file. See the help topic <location> for exceptions

我知道有类似的问题 issue.I 我正在做一个 .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.