Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC4 Custom 404 page?

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)

like image 550
TTT Avatar asked Nov 06 '12 20:11

TTT


People also ask

How do I find a custom error page?

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.


2 Answers

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.

like image 161
Ed DeGagne Avatar answered Sep 23 '22 17:09

Ed DeGagne


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.

like image 35
Josh Wheelock Avatar answered Sep 24 '22 17:09

Josh Wheelock