如何使用 jscript 断言来过滤 Elmah 1.1 RC 中的异常类型?

发布于 2024-07-22 05:02:08 字数 1034 浏览 12 评论 0原文

针对 404 的第一个绑定有效,因此我正确设置了 ErrorFilterModule,但 jscript 部分似乎根本不起作用。 HttpRequestValidationException 仍在报告邮件中发送。

<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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪之魂 2024-07-29 05:02:08

当您有多个条件时,按照示例中的方式( 然后 ),您需要告诉 ELMAH 要么 AND他们或或他们。 解决方案是使用 ,具体取决于您希望如何逻辑组合条件。 下面,我对两者进行了“或”运算,以便任一条件都适用:

<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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文