Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elmah reporting unwanted 404 errors

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.

I assume this is a scanner trying to find vulnerabilities. Because I am not running PHP I am safe! However I would like to stop ELmah reporting this error.

Whats the best way to exclude these types of errors from being reporting without actually creating a /prx2.php page. I also would like to do this in a config file rather than doing it progmatically.

Any ideas?

like image 279
Rippo Avatar asked Jan 15 '10 12:01

Rippo


People also ask

What is ELMAH used for?

Summary. ELMAH provides a simple, yet powerful mechanism for logging errors in an ASP.NET web application. Like Microsoft's health monitoring system, ELMAH can log errors to a database and can send the error details to a developer via email.

What is ELMAH error?

ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.

Does ELMAH work with .NET core?

ELMAH doesn't support ASP.NET Core.

What is ELMAH .NET core?

Elmah (which stands for Error Logging Modules and Handlers) is a pluggable error management framework. Because Elmah can be used to attach error logging capabilities to your application without having to re-compile or re-deploy, it makes the process of detecting application errors almost seamless.


2 Answers

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

like image 196
saret Avatar answered Oct 18 '22 18:10

saret


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>
like image 41
Ondrej Svejdar Avatar answered Oct 18 '22 18:10

Ondrej Svejdar