Monday, April 11, 2011

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?

From stackoverflow
  • Hi, check out the HandleError attribute. There's a good write up here and here.

    yapiskan : That's what I'm looking for. Thanks!
  • 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.

    yapiskan : I have a base controller. I guess it is enough to put this filter to base class. Am I right?
    Kieron : It should be, give it a go...

0 comments:

Post a Comment