配置部分“ system.web / httpModules”已经定义。每个配置文件中的节只能出现一次。有关异常,请参见帮助主题<location>。

时间:2019-04-11 16:56:42

标签: asp.net .net web-config configuration-files elmah

我知道存在与此问题类似的问题。我正在开发一个.Net项目,直到昨天为止,它的运行状况都很好。今天,我在配置文件中看到一个错误。

我得到的错误:

'Config节'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>

1 个答案:

答案 0 :(得分:1)

您将两次添加所有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元素。