我无法让我的Elmah电子邮件过滤器工作

时间:2012-05-29 12:50:20

标签: c# .net elmah

我有关于以下web.config设置和Elmah的查询。问题是,当我不想要的时候,我仍然收到有关公共行动方法问题的电子邮件。我现有的过滤器似乎不起作用。

我不完全确定AND和OR应该如何在Elmah电子邮件过滤中工作,特别是因为这些代码是从我从其他开发人员那里获得的一些项目工作中删除的。

标签旨在防止通过电子邮件报告任何错误,其中包含任何单词索引,缓存或登录。

有人可以帮忙吗?

<configuration>
    <configSections>
        <!--Elmah sectionGroup-->
        <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>  

 <elmah>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
<errorMail from="" to="" subject="Error(Elmah)" async="true " />
    <security allowRemoteAccess="1"/>
<errorFilter>
  <test>
    <or>
        <is-type binding="BaseException" type="System.InvalidOperationException" />
</or>
<or>
    <regex binding="Exception.Message" pattern="(?ix: \b potentially \b.+?\b dangerous \b.+?\b value \b.+?\b detected \b.+?\b client \b )" />
</or>
<or>
    <regex binding="Exception.Message" pattern="(?ix: \b public action method     'Index' was not found on controller \b )" />
    <regex binding="Exception.Message" pattern="(?ix: \b public action method 'cache' was not found on controller \b )" />
    <regex binding="Exception.Message" pattern="(?ix: \b public action method 'Login' was not found on controller \b )" />
</or>
  </test>
</errorFilter>
  </elmah>  
  <location path="elmah.axd">
  </location>  
  <system.web>
  </system.web>
 <system.webServer>    
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</modules>
<handlers>
  <add name="httpHandler" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
   </handlers>
  </system.webServer>
</configuration>

1 个答案:

答案 0 :(得分:3)

test元素只能有一个子断言,因此在其下面有多个or元素意味着除了第一个之外的所有元素都被忽略。根据您的描述,您的test元素应该是这样读取的:

<test>
  <or> 
    <is-type binding="BaseException" type="System.InvalidOperationException" /> 
    <regex binding="Exception.Message" pattern="(?ix: \b potentially \b.+?\b dangerous \b.+?\b value \b.+?\b detected \b.+?\b client \b )" /> 
    <and> 
      <regex binding="FilterSourceType.Name" pattern="mail" />
      <regex binding="Exception.Message" pattern="(?ix: \b public \s action \s method \s '(Index|cache|Login)' \s was \s not \s found \s on \s controller \b )" /> 
    </and>
  </or> 
</test>

请注意,我还继续将三个regex元素折叠成一个并修复了模式以正确分隔单词(边缘为\b,中间为\s