如果你使用的方法的Application_Error在ASP.NET MVC你的Global.asax? [英] Should you use the method Application_Error in your global.asax in ASP.NET MVC?

查看:152
本文介绍了如果你使用的方法的Application_Error在ASP.NET MVC你的Global.asax?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,在ASP.NET人们通常把所谓的的Application_Error一个受保护的方法在其Global.asax文件序处理说,<一个href=\"http://stackoverflow.com/questions/434859/handling-applicationerror-in-asp-net-apps-global-asax\">logging例外的。

I know that in ASP.NET people typically put a protected method called "Application_Error" in their global.asax file inorder to handle say, logging of exceptions.

我的问题是,这是一个ASP.NET唯一的事情,或者它在ASP.NET MVC同样出色的工作?它是一个ASP.NET MVC的最佳做法或不?

My question is, is this an ASP.NET only thing, or does it work equally well in ASP.NET MVC? Is it an ASP.NET MVC best practice or not?

推荐答案

您应该使用异常过滤器来处理在控制器中的例外。您可以通过添加[的HandleError]属性的控制器动作做到这一点。进一步的信息可以发现:在 MS MVP MVC博客

You should be using the Exception Filter to handle exceptions in your controllers. You do this by adding the [HandleError] attribute to the controller action. Further information can be found at: on the MS MVP MVC Blog

这篇关于如果你使用的方法的Application_Error在ASP.NET MVC你的Global.asax?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆