1

There is a routing table that includes

 routes.MapRoute("404-PageNotFound", "{*url}", new { controller = "Error", action = "PageNotFound" });

The web.config has:

<customErrors mode="RemoteOnly">        
   <error statusCode="404" redirect="/Error/PageNotFound" />
</customErrors>

The ErrorController gets hit when no Route Matches and the View for errors get rendered using:

public ActionResult PageNotFound(ViewModelBase model)
 {
     return View(model);
}

The status code for the response is 200, but in this case a 404 is required. Is there a way to return http code 404 and a custome errorpage?

1 Answer 1

5
public ActionResult PageNotFound(ViewModelBase model)
{
    Response.StatusCode = 404;
    return View(model);
}
Sign up to request clarification or add additional context in comments.

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.