I have the following route at the bottom of my global.asax:
routes.MapRoute(
"404-PageNotFound",
"{*url}",
new { controller = "Error", action = "PageNotFound" }
);
Which works fine in Visual Studio, but during production I get a page with an IIS error.
Should this route not catch any URL that was not discovered by others, so there is no 404 in terms of IIS? Is there anything else I need to do in web.config?
Note. I do not want to redirect the 404 URL; rather, I serve the 404 error page at the requested URL (I believe this is the right approach in terms of usability).
UPDATE
In my error controller, I install Response.StatusCode = 404;what seems to be the problem. When I delete this and deploy it back into production, I get my pages again with a friendly error. However, I believe that I need the 404 status in the HTTP header - for SEO purposes - so my question now becomes this:
REVISED QUESTION
How / why IIS intercepts the response and sends its original 404 error and how to prevent this?
** Decision **
Dommer receives a prize for an offer Response.TrySkipIisCustomErrors=true;that (I think) was needed. But there were two more key details:
- user errors should be included in web.config (duh!) and
- action 404 must have the [HandleErrors] attribute.
URL- , "404-PageNotFound", , 404, :
[HandleError]
public ActionResult NotFound()
{
Response.StatusCode = 404;
Response.TrySkipIisCustomErrors = true;
return View("PageNotFound", SearchUtilities.GetPageNotFoundModel(HttpContext.Request.RawUrl));
}
, , , :
return NotFound();
: RedirectToAction()
:
, , URL- 404.