如何使用 jscript 断言来过滤 Elmah 1.1 RC 中的异常类型?
针对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您有多个条件时,按照示例中的方式(
然后
),您需要告诉 ELMAH 要么 AND他们或或他们。 解决方案是使用
或
,具体取决于您希望如何逻辑组合条件。 下面,我对两者进行了“或”运算,以便任一条件都适用:当您直接在
下有多个条件且没有逻辑(
或
) 组合,则仅使用第一个,这就是为什么您的
组合被忽略。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: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.