ASP.NET MVC全局错误处理与ELMAH - 最佳实践 [英] ASP.NET MVC Global Error Handling with ELMAH - best practices
问题描述
我真的想ELMAH融入我MVC4应用程序,但我有一些问题:
I really would like to integrate ELMAH into my MVC4 application but I'm having a few issues:
-
如果ELMAH重定向所有的错误到一个特定的错误页面,我只需要返回成功(如更新,删除,...)到用户?
if elmah redirects all errors to a specific error page, do I only need to return success (eg for update, delete, ...) to the user?
如果ELMAH捕获所有的错误,我需要处理错误(例如,使用尝试捕捉
块)在我所有的code?
if elmah catches all errors do i need to handle errors (e.g. use try catch
blocks) in my code at all?
有一个最佳实践的例子的地方如何使用ELMAH?
is there a best practise example somewhere how to use ELMAH?
推荐答案
1)ELMAH不会做任何重定向,所以你必须自己处理错误页面,在web.config中(热OT做到这一点,你可以看看<一个href=\"http://weblogs.asp.net/nannettethacker/archive/2012/01/15/custom-error-pages-and-404-page-not-found-error-web-config-setup.aspx\"相对=nofollow>这里)
1) Elmah does do any redirects, so you have handle error pages yourself in web.config (hot ot do this you can look here)
2),你应该。 ELMAH是用于记录未处理的异常。您可以登录处理的异常是这样的:
2) You should. Elmah is for logging unhandled exceptions. You can log handled exceptions like this:
try
{
.....
}
catch(Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
3)有一个很好的文章斯科特Hanselman的博客:ELMAH:错误日志记录模块和处理为ASP.NET(和MVC呢!)
这篇关于ASP.NET MVC全局错误处理与ELMAH - 最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!