I have an Elmah filter setup in web.config to stop notification of certain error messages. But they still seem to come through. What could be the cause?
<httpModules>
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="SecuritySwitch" type="SecuritySwitch.SecuritySwitchModule, SecuritySwitch" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<errorFilter>
<test>
<regex binding="Exception.Message" pattern="(?ix: \b This \b.+?\b is \b.+?\b an \b.+?\b invalid \b.+?\b webresource \b.+?\b request \b )" />
</test>
<test>
<regex binding="Exception.Message" pattern="(?ix: \b Path \b.+?\b eurl.axd \b )" />
</test>
<test>
<regex binding="Exception.Message" pattern="(?ix: \b potentially \b.+?\b dangerous \b.+?\b value \b.+?\b detected \b.+?\b client \b )" />
</test>
</errorFilter>
I believe you can only have single test element. The key is to start with an <or></or>
element and nest your filters in that. This certainly works for us.
<errorFilter>
<test>
<or>
<!-- Don't email 404 errors -->
<and>
<equal binding="HttpStatusCode" value="404" type="Int32" />
<regex binding="FilterSourceType.Name" pattern="mail" />
</and>
<!-- Don't log cancelled downloads -->
<and>
<equal binding="HttpStatusCode" value="500" type="Int32" />
<equal binding="Context.Request.ServerVariables['URL']" value="/Download.aspx" type="String" />
<or>
<regex binding="BaseException.Message" pattern="0x80070016" caseSensitive="false" />
<regex binding="BaseException.Message" pattern="0x800704CD" caseSensitive="false" />
</or>
</and>
<!--Viewstate Corruption-->
<or>
<regex binding="Exception" type="System.Web.HttpException" pattern="System.FormatException: Invalid length for a Base-64 char array." caseSensitive="false" />
<regex binding="Exception" type="System.Web.HttpException" pattern="System.FormatException: Invalid character in a Base-64 string." caseSensitive="false" />
</or>
<!-- IE8 Bug -->
<and>
<regex binding="Context.Request.ServerVariables['HTTP_USER_AGENT']" pattern="Trident\/4\.0" />
<or>
<equal binding="Context.Request.ServerVariables['URL']" value="/ScriptResource.axd" type="String" />
<equal binding="Context.Request.ServerVariables['URL']" value="/WebResource.axd" type="String" />
</or>
</and>
</or>
</test>
</errorFilter>
More information here:
http://www.diaryofaninja.com/blog/2011/09/20/adding-filters-to-your-elmah-installation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With