my question is regarding Pure.Kromes answer to this post. I tried implementing my pages\' custom error messages using his method, yet there are some problems I can\'t quite
I got it to work. It seems my understanding of the problem was somewhat wrong to begin with.
In the web.config, I changed the following:
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Views/Error/ServerError.cshtml">
<error statusCode="404" redirect="~/Views/Error/NotFound.cshtml" />
</customErrors>
... and ...
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/NotFound" responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" path="/ServerError" responseMode="ExecuteURL" />
</httpErrors>
This directly redirects to the views. My understanding was that I had to redirect to the error controller which in turn would redirect to the views, but apparently this was not the case. I'd like to thank you for your comments as they have made me analyze the problem again when I was already about to just ditch the custom error stuff and simply be lazy and display YSOD's. :)
there is one more issue with that setup, when you have more complex routes and have several segments ex.
http://localhost:2902/dsad/dadasdmasda/ddadad/dadads/ddadad/dadadadad/
I got server error ->
Sorry, an error occurred while processing your request.
Exception: An error occured while trying to Render the custom error view which you provided, for this HttpStatusCode. ViewPath: ~/Views/Error/NotFound.cshtml; Message: The RouteData must contain an item named 'controller' with a non-empty string value.
Source:
my solution for that was to add additional route at the end after default route
routes.MapRoute(
"Default Catch all 404",
"{controller}/{action}/{*catchall}",
new { controller = "Error", action = "NotFound" }
);
hope it could help someone:-)