Best practices for error handling within MVC (that correctly account for all scenarios)
Correct error handling is more complicated than just working with HandleErrorAttribute or <customErrors>. Good error handling should account for a variety of scenarios:
* 404 errors that preserve the path and return the correct error code
* 500 status codes for uncaught exceptions
* Dealing with errors that operate outside of the context of a controller (which may not be matched)
* Pages that result in errors likely shouldn't be cached, especially if the error is transient
* Accounting for the possibility of unsafe paths in the request
* Logging errors so that they're not lost
* Rendering error pages that preserve a site's layout
There is competing (and misleading?) information out there, both within ASP.NET documentation and provided by users. Any direction would be greatly appreciated!
This is a great idea, hopefully we’ll get a few votes.
In addition, I’d like to see how to handle exceptions triggered by AJAX calls.
How to globally handle 400, 401, 403, 404, 500 and perhaps show a bootstrap modal for example.