Elmah reporting unwanted 404 errors

前端 未结 2 1113
萌比男神i
萌比男神i 2021-01-07 22:10

I am using Elmah for logging in a ASP.NET MVC project and I am recieving lots of 404 errors for a path /prx2.php which in turn is passing a hash as a querystring param.

相关标签:
2条回答
  • 2021-01-07 22:21

    Elmah supports error filtering - Error Filtering link

    This should solve the issue for you. You can either define your filter through code - in the Global.asx file, or within the xml config for elmah itself

    0 讨论(0)
  • 2021-01-07 22:27

    Step1: Configure config sections to include elmah errorFilter section:

    <configSections>
      <sectionGroup name="elmah">
        <!-- ... -->  
        <!-- this is the important part -->
        <section name="errorFilter" requirePermission="false" 
          type="Elmah.ErrorFilterSectionHandler, Elmah"/>
      </sectionGroup>
    </configSections>
    

    Step2: Configure the filter itself in <elmah> section.

    <elmah>
      <!-- ... -->
      <errorFilter>
        <test>
          <and>
            <equal binding="HttpStatusCode" value="404" type="Int32" />
            <!-- you may want to consider something more generic like pattern="/.+[.]php" -->
            <regex binding="Context.Request.Url" pattern="/prx2.php" />
          </and>
        </test>
      </errorFilter>
    </elmah>    
    

    Step3: Include the Elmah.ErrorFilterModule inside your application modules

    Modern (IIS7+) version of including http module:

    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true">
        <!-- ... -->
        <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" 
          preCondition="managedHandler" />
      </modules>
    </system.webServer>
    

    Legacy (older IIS) version of including http module:

    <system.web>
      <httpModules>
        <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
      </httpModules>
    </system.web>
    
    0 讨论(0)
提交回复
热议问题