I've got my customErrors
mode set to On and redirecting to:
Here's my view in my solution:
Whenever I have an unhandled exception, my app redirects me to the Error page, as expected. But, I lose the exception information, because, I'm assuming, the app is redirecting. I even tried redirectMode="ResponseRewrite"
in the customErrors element, but that didn't work.
So, here's my "Index" view on my Error controller, which the app is redirecting to- notice the model:
And further down, I have:
But, @Model is null. How can I get the exception information from a customErrors redirect?
To get that model, you need to use the
HandleErrorAttribute
filter to catch the error. You can see instructions here: http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/handleerrorattribute-or-error-handling-in-mvc-4/TL;DR:
Disable the redirect, but make sure custom errors are still on:
Make sure the
HandleErrorAttribute
filter is registered globally (it is by default):Move/rename your error view to
~\Views\Shared\Error.cshtml