1

I hav asp.net mvc 3 application.

When user pass id of non existing object I return 404 view in this way:

Response.StatusCode = 404;
return View("404");

Locally all works fine and I have my custom error page. But on production, I have standart asp.net 404 page. I try to set customErrors either to "on" or "off" - results is the same.

st78
  • 7,657
  • 11
  • 48
  • 64

2 Answers2

1
<system.webServer>
    ...
    <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" 
            path="/errors/404" responseMode="ExecuteURL" />
    </httpErrors>

Also, there is a new way you can return 404 from an action method:

// Response.StatusCode = 404;
// return View("404");
return HttpNotFound();
danludwig
  • 46,166
  • 21
  • 156
  • 234
0

Found solution here: Routing for custom ASP.NET MVC 404 Error page

Set another magic setting in web config under system.webServer section:

<httpErrors errorMode="Detailed" />
Community
  • 1
  • 1
st78
  • 7,657
  • 11
  • 48
  • 64