5

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)

TTT
  • 1,848
  • 2
  • 30
  • 60

2 Answers2

10

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.

Ed DeGagne
  • 3,250
  • 1
  • 30
  • 46
  • 1
    I've tried this numerous times, but it keeps displaying the default asp error page – Sinaesthetic Jul 18 '13 at 21:46
  • Did you also create an error controller and the views? http://stackoverflow.com/questions/13905164/how-to-make-custom-error-pages-work-in-asp-net-mvc-4 – Ed DeGagne Jul 19 '13 at 12:51
  • 3
    I did. However, I found my problem. I was actually returning an HttpStatusCodeResult like the framework would, normally. Apparently, that isn't picked up as an error so the custom error pages never get called. I changed my code to throw an HttpException instead and it works now. Not sure how I feel about it – Sinaesthetic Jul 19 '13 at 17:29
3

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.

Josh Wheelock
  • 369
  • 4
  • 9