kco*_*ode 4 error-handling elmah exception-handling web-config
有没有办法使用异常消息过滤elma中的异常?
示例:
"System.Web.HttpException:Request timed out." 我不想过滤掉所有HttpException,只过滤掉超时请求.
"System.Web.HttpException:超出了最大请求长度."
我不想做的是为此编写自己的代码.那么有可能使用buildin-web.config配置吗?
谢谢!
Dre*_*ing 11
是的你可以.只需使用正则表达式来查询消息.有关如何比较异常消息的详细信息,请参阅下面的示例.
<errorFilter>
<test>
<!-- http://groups.google.com/group/elmah/t/cbe82cee76cc6321 -->
<and>
<is-type binding='Exception'
type='System.Web.HttpException, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' />
<regex binding='Exception.Message'
pattern='invalid\s+viewstate'
caseSensitive='false' />
<regex binding='Context.Request.UserAgent'
pattern='Trident/4(\.[0-9])*'
caseSensitive='false' />
</and>
</test>
</errorFilter>
Run Code Online (Sandbox Code Playgroud)
您可以在global.asax中设置事件处理程序,以避免丑陋的配置正则表达式设置:
void ErrorMail_Filtering(object sender, Elmah.ExceptionFilterEventArgs e)
{
if (e.Exception.Message.Contains("Request timed out"))
e.Dismiss();
}
Run Code Online (Sandbox Code Playgroud)
请参阅错误过滤.
| 归档时间: |
|
| 查看次数: |
3351 次 |
| 最近记录: |