如何使用JScript断言来过滤Elmah 1.1 RC中的异常类型?
-
06-09-2019 - |
题
与404的第一个绑定作品,因此我得到了正确设置的错误filtermedule,但是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>
解决方案
当您有多个条件时,您的示例中的方式(<equal>
然后 <jscript>
),您需要告诉Elmah和他们或他们或他们。解决方案是使用 <and>
或者 <or>
, ,取决于您要如何逻辑地结合条件。下面,我有两者,因此条件可以适用:
<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>
当您直接有多个条件时 <test>
没有逻辑(<and>
或者 <or>
)然后只使用第一个组合,这就是为什么您的 <jscript>
一个人被忽视。
不隶属于 StackOverflow