Is there a built in or a proper way to handle errors in asp.net mvc 3?
This is what I want to do:
- If the application crashes, or throws an error, it goes to a specific error page.
- I can throw my own error from the controller action. (and it goes to an error page).
I found the following ways:
- I see there is a long way to do it
here. (for v1 and v2 but also
applies to v3). - Using errorhandle attribute here.
How do I handle this the proper way?
If the solution is similar or is like #1 in the list above, I am using ninject and I have not created a base class. How do I still do this?
For Global Error Handling
All you have to do is change the customErrors mode=”On” in web.config page
Error will be displayed through Error.cshtml resides in shared folder.
Make sure that Error.cshtml Layout is not null.
[It sould be something like: @{ Layout = “~/Views/Shared/_Layout.cshtml”; }
Or remove Layout=null code block]
A sample markup for Error.cshtml:-
For Specific Error Handling
Add HandleError attribute to specific action in controller class. Provide ‘View’ and ‘ExceptionType’ for that specific error.
A sample NotImplemented Exception Handler: