ASP.NET MVC: How to serve content while returning status code 404?

Posted by Marek on Stack Overflow See other posts from Stack Overflow or by Marek
Published on 2010-03-30T18:24:06Z Indexed on 2010/03/31 0:43 UTC
Read the original article Hit count: 507

Filed under:
|
|
|

I would like to serve a user friendly "not found" page in my ASP.NET MVC application while providing a 404 status code. (based on this answer)

I already have the mechanism how to catch an invalid route and the custom 404 page is served by my ErrorController/Handle404 action.

My current implementation of Handle404:

    public ActionResult Handle404()
    {
        Response.StatusCode = 404;
        return View("NotFound");
    }

Currently, IIS serves the page as 404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable. (the standard IIS page, not my user friendly content)

How can I include the 404 status code in the result served by the Handle404 action while still serving the content?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about 404