st78
st78

Reputation: 8316

CustomErrors on doesn't work on production

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.

Upvotes: 1

Views: 686

Answers (2)

st78
st78

Reputation: 8316

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" />

Upvotes: 0

danludwig
danludwig

Reputation: 47375

<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();

Upvotes: 1

Related Questions