I've place this in web.config <system.webServer>
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" path="/cv/" responseMode="ExecuteURL" />
</httpErrors>
The path that is used temporarily here [myapplication]/cv/ returns a page.
But if I go to [myapplication]/[anything that doesn't exists] to get a 404 response, juste nothing happens.
This is currently working on my old web form site, but I can't get it working on a MVC4 site. How can I make this work ? (I don't want to use the "Redirect/File" methods)
To display a custom error page with an appropriate error code, use the <httpErrors> section only, and do not use the <customErrors> section. Add the following <httpErrors> section under <system. webServer> section, as shown below.
This is what I have in a current MVC 4 project:
<customErrors mode="On" defaultRedirect="~/Error/General">
<error statusCode="404" redirect="~/Error/Http404" />
</customErrors>
I have an Errors controller, and views for "General" and "Http404" (action methods).
Works like a charm.
Part of the problem might also stem from the fact that the <customErrors>
tag is not a valid child of <system.webServer>
. Try putting it in <system.web>
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With