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)

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I've tried this numerous times, but it keeps displaying the default asp error page
Did you also create an error controller and the views? stackoverflow.com/questions/13905164/…
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
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.