Creating a custom error page in MVC 5 is not too difficult. If you want to have one that is server farm friendly, well that is not too tough either. I created a little demo project for doing custom errors that passes a model around. To be effective in handling uncaught errors we will need to use the Global.asax Application_Error method. You can also use this method to send errors that you catch but just cannot handle or fail out of gracefully.
There are a number of reasons why you may want to do custom errors like I do below.
- You are in a server farm or other environment where Session based objects will not work
- Display a user friendly message based on the error received
- Display a user friendly message based on an HTTP Code (if one was returned)
- Log the error
- Send a notification of the error