I want to transfer all unhandled exceptions to an error page in Asp.Net MVC. What is the way to handle the unhandled exceptions in Asp.net MVC? Is there anything like application_error?
我想将所有未处理的异常转移到Asp中的错误页面。净MVC。在Asp.net MVC中处理未处理的异常的方法是什么?有类似application_error的东西吗?
2 个解决方案
#2
2
If you are using the standard setup, your controller(s) can do this by overriding one of the methods (proabably OnException
, but I don't have it handy to check). If you want all your controllers to share this logic, you can use a base-controller.
如果您正在使用标准设置,那么您的控制器可以通过覆盖其中一个方法(可能是OnException,但是我没有方便的检查方法)来实现这一点。如果希望所有控制器共享此逻辑,可以使用基本控制器。
Alternatively, you can do this via filters (for example [HandleError]
). I don't know if there is a single global place for such logic, though.
或者,您可以通过过滤器(例如[HandleError])来实现这一点。不过,我不知道这种逻辑是否存在一个单一的全局位置。
#1
#2
2
If you are using the standard setup, your controller(s) can do this by overriding one of the methods (proabably OnException
, but I don't have it handy to check). If you want all your controllers to share this logic, you can use a base-controller.
如果您正在使用标准设置,那么您的控制器可以通过覆盖其中一个方法(可能是OnException,但是我没有方便的检查方法)来实现这一点。如果希望所有控制器共享此逻辑,可以使用基本控制器。
Alternatively, you can do this via filters (for example [HandleError]
). I don't know if there is a single global place for such logic, though.
或者,您可以通过过滤器(例如[HandleError])来实现这一点。不过,我不知道这种逻辑是否存在一个单一的全局位置。