以声明方式配置ELMAH过滤

时间:2011-09-21 16:14:55

标签: elmah

我想在web.config中以声明方式过滤ELMAH结果。我没有成功地过滤掉我想要的一些例外。 HttpStatusCode成功过滤,但我仍然通过ViewStateExceptions。有很多关于如何配置它的帖子,但是我不确定如何在配置部分放置几个过滤器,文档似乎在这一点上有点薄。目前我的web.config中有以下配置。我想知道,有人可以指出:

  1. 如果我已经正确定义了东西以过滤掉ViewStateExceptions和
  2. 如何正确定义节点结构以正确处理所有过滤器。

    <errorFilter>
        <test>
            <equal binding="HttpStatusCode" value="404" type="Int32" />
        <test>
        <test>
            <and>
                <is-type binding="Exception" type="System.Web.HttpException" />
                <regex binding='Exception.Message' pattern='invalid\s+viewstate' caseSensitive='false' />
            </and>
        </test>
        <test>
            <and>
                <is-type binding="Exception" type="System.Web.UI.ViewStateException" />
                <regex binding='Exception.Message' pattern='invalid\s+viewstate' caseSensitive='false' />
            </and>
        </test>
    </errorFilter>
    

1 个答案:

答案 0 :(得分:5)

在上一次测试中尝试绑定到BaseException,而不是Exception。

你的结构尝试类似:

  <test>
    <or>
       <regex binding="BaseException.Message" pattern="Request timed out."/>
       <and>
          <equal binding="Context.Request.ServerVariables['REMOTE_ADDR']" value="::1" type="String"/>
          <regex binding="Exception" pattern="hello"/>
       </and>
      <regex binding="BaseException.Message" pattern="The remote host closed the connection."/>
    </or>
  </test>

应该有效。将所有测试包裹在<or>中,然后将所有必须为真的测试包裹在<and>中。