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?
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.
check out the HandleError attribute. There's a good write up here.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With