Is there a way to return the same view every time a HttpNotFoundResult is returned from a controller? How do you specify this view? I\'m guessing configuring a 404 page in
Here is true answer which allows fully customize of error page in single place. No need to modify web.confiog or create sophisticated classes and code. Works also in MVC 5.
Add this code to controller:
if (bad) {
Response.Clear();
Response.TrySkipIisCustomErrors = true;
Response.Write(product + I(" Toodet pole"));
Response.StatusCode = (int)HttpStatusCode.NotFound;
//Response.ContentType = "text/html; charset=utf-8";
Response.End();
return null;
}
Based on http://www.eidias.com/blog/2014/7/2/mvc-custom-error-pages