Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle general exceptions in Asp.Net MVC?

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?

like image 909
Ali Ersöz Avatar asked Mar 06 '09 11:03

Ali Ersöz


People also ask

How is exception handling done in MVC?

Building Web Applications with ASP.NET Core 3 MVC In ASP.NET, error handling is done using the standard try catch approach or using application events. ASP.NET MVC comes with built-in support for exception handling using a feature known as exception filters.


2 Answers

check out the HandleError attribute. There's a good write up here.

like image 76
Kieron Avatar answered Sep 22 '22 19:09

Kieron


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.

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.

like image 29
Marc Gravell Avatar answered Sep 23 '22 19:09

Marc Gravell