views:

385

answers:

1

The first binding against 404 works so I got the ErrorFilterModule set up properly, but the jscript section does not seems to work at all. HttpRequestValidationException is still being send in the report mail.

<errorFilter>
  <test>
    <equal binding="HttpStatusCode" value="404" type="Int32" />
    <jscript>
      <![CDATA[
            // @assembly mscorlib
            // @assembly System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
            // @import System.IO
            // @import System.Web

            HttpStatusCode == 404
            || BaseException instanceof FileNotFoundException 
            || BaseException instanceof HttpRequestValidationException
            || BaseException instanceof HttpException
            /* Using RegExp below (see http://msdn.microsoft.com/en-us/library/h6e2eb7w.aspx) */
            || Context.Request.UserAgent.match(/crawler/i)
            || Context.Request.ServerVariables['REMOTE_ADDR'] == '127.0.0.1' // IPv4 only
            ]]>
    </jscript>
  </test>
</errorFilter>
+2  A: 

When you have more than one condition, the way you have it in your example (<equal> then <jscript>), you need to tell ELMAH to either AND them or OR them. The solution is to use <and> or <or>, depending on how you want to logically combine the conditions. Below, I have OR-ed the two so either the condition may apply:

<errorFilter>
  <test>
    <or>
        <equal binding="HttpStatusCode" value="404" type="Int32" />
        <jscript>
          <expression><![CDATA[
                // @assembly mscorlib
                // @assembly System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
                // @import System.IO
                // @import System.Web

                HttpStatusCode == 404
                || BaseException instanceof FileNotFoundException 
                || BaseException instanceof HttpRequestValidationException
                || BaseException instanceof HttpException
                /* Using RegExp below (see http://msdn.microsoft.com/en-us/library/h6e2eb7w.aspx) */
                || Context.Request.UserAgent.match(/crawler/i)
                || Context.Request.ServerVariables['REMOTE_ADDR'] == '127.0.0.1' // IPv4 only
          ]]></expression>
        </jscript>
    </or>
  </test>
</errorFilter>

When you have multiple conditions directly under <test> with no logical (<and> or <or>) combination then only the first one is used, which is why your <jscript> one was being neglected.

Atif Aziz
Hi and thanks for the info about <or>. The BaseException-filters does how ever still not work. HttpRequestValidationException is still reported by Elmah with the code above.
jesperlind
That was my bad. The example was missing the <expression> element, within with the whole JScript code should be wrapped.
Atif Aziz
Excellent, now it's working! Thank you very much for your help with this.
jesperlind