Similar questions have been asked over and over but for some reason none of the things I have tried have worked. I have an ajax application and when the user request an invalid url I would like to return a JsonResult that looks something like this:
[ error: true, status: 404, message: 'The requested page could not be found... or some other message... ']
I don't want the user to just be redirected to the error page defined in the web.config file as that would take them out of the ajax application.
I have tried the following things:
- Custom HandleErrorAttribute - Turns out these only handle 500 errors due to exceptions thrown by my code
- Custom FilterAttribute that extends FilterAttribute and implements IExceptionFilter - Same issue as before
- Override HandleUnknownAction in the Base Controller - Couldn't figure out how to return a JsonResult from the method
- Added a catch all route - My other routes are being used before the catch all route is found
Any thoughts would be appreciate.