【问题标题】:Specifying filters for ELMAH in web.config在 web.config 中为 ELMAH 指定过滤器
【发布时间】:2012-07-06 21:02:02
【问题描述】:

当我的 asp.net 应用程序中出现这 2 个异常中的任何一个时,我有兴趣为 ELMAH 指定过滤器。

  1. 异常消息包含“这是一个无效的网络资源请求”
  2. 异常消息包含“潜在危险...值...”

我在我的 web.config 中使用了以下内容,但它只过滤无效的 websresource 请求,如果它被放置为第一个过滤器,但如果它被放置为第二个过滤器,则它不适用。配置文件“errorfilter”元素如下所示。如何在 web config 中同时指定这两个条件,是否需要使用 BaseException.Message 或 Exception.Message?

    <errorFilter>
    <test>
     <or>
       <and>
        <regex binding="Exception.Message" pattern="(?ix: \b potentially \b.+?\b  
            dangerous \b.+?\b value \b.+?\b detected \b.+?\b client \b )" />
      </and>  
    </or>
    <or>
      <and>
          <equal binding="BaseException.Message" value="This is an invalid webresource
          request." type="String" />
      </and>
    </or>
    </test>   
    </errorFilter>

【问题讨论】:

    标签: elmah


    【解决方案1】:

    test 元素只能有一个子元素。由于您有两个 or 条件,因此只有第一个被应用。 您的两个条件的正确方法是将它们分组到单个or 元素下,在test 下,如下所示:

    <errorFilter>
      <test>
        <or>
            <regex binding="Exception.Message" 
                   pattern="(?ix: \b potentially \b.+?\b  
                            dangerous \b.+?\b value \b.+?\b 
                            detected \b.+?\b client \b )" />
            <equal binding="BaseException.Message" 
                   value="This is an invalid webresource request." 
                   type="String" />
        </or>
      </test>
    </errorFilter>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 1970-01-01
      • 2011-02-20
      • 2018-01-16
      • 1970-01-01
      • 2010-11-15
      相关资源
      最近更新 更多