在 ELMAH 获取异常之前捕获异常并清除它
我遇到一个问题,我在 Global.asax 中捕获了一个异常。作为此异常处理的一部分,由于此异常,我将用户重定向到特定页面。
我还使用插入的电子邮件模块进行 ELMAH 错误处理。我不想收到有关此异常的电子邮件。我也不想将这种类型的异常添加到 ELMAH 忽略列表中,以防我想围绕异常进行精细工作(即,仅当它与某些属性匹配、发生在某些页面上时)
我想:
- 写一个 <代码>Application_OnError 将用户重定向到
Application_OnError
中的页面(我知道如何执行这部分,更多关于我将其留在这里的过程) - 停止 ELMAH 捕获此错误后收到此错误
我当前正在 App_OnError
方法中调用 Server.ClearError()
,但仍然收到这些电子邮件。
I have a problem where I have an exception being thrown that I am capturing in Global.asax. As part of this exception handling I redirect the user to a specific page because of this exception.
I also have ELMAH error handling with the email module plugged in. I do not want to receive emails for this exception. I also don't want to add this type of exception to ELMAHs ignore list, in case I want to do granular work around the exception (i.e., only if it matches certain properties, happens on certain pages)
I want to:
- write an
Application_OnError
that
redirects a user to a page (I know how to do this part, more for procedure I've left it here) - in the
Application_OnError
stop ELMAH from
receiving this error after I've caught it
I am currently calling Server.ClearError()
inside my App_OnError
method, but am still receiving these emails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 ELMAH 文档,
我保留了我的
Application_OnError
方法在我的 Global.asax 中,但我还添加了以下全局方法:如果它是与我想要的类型匹配的类型,则忽略 ELMAH 异常 - 在我的例子中是
HttpRequestValidationException
。仅当您打开了错误邮件过滤器时才需要
ErrorMail_Filtering
方法 - 我就是这么做的。As per the ELMAH documentation
I put leave my
Application_OnError
method in my Global.asax but I also add the following global methods:What this does is dismiss the ELMAH exception if it is the type that matches what I want - in my case the
HttpRequestValidationException
.The
ErrorMail_Filtering
method is only required if you have the error mail filter turned on - which I do.您是否也使用
[HandleError]
属性?我要做的方法是:HandleError
属性,并且不会在我不想让 ELMAH 参与的操作上应用该属性。Application_Error
代码将按原样存在。Are you using
[HandleError]
attribute as well? The way I would do is:HandleError
attribute for action level and will not apply the attribute on the action where I don't want to get ELMAH involved.Application_Error
code will exists as is.