views:

110

answers:

1

This question is related to this, hopefully better phrased.

I would like to serve a custom 404 page from ASP.NET MVC. I have the route handler and all the infrastructure set up to ensure that nonexistent routes are handled by a single action:

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

Problem: IIS serves back its own content (some predefined message) when I set Response.StatusCode to 404 before returning the content.

On the VS development web server, this works as intended - the status code of the HTTP response is 404 while my content (the NotFound view) is served.

I believe that when the IIS processing pipeline sees that the application returns 404, it simply replaces the whole response with its own.

What setting in IIS affects this behavior?

I do not have access to the IIS installation so I can not investigate this - however, I can ask the hosting provider to tweak the configuration for me if I know what exactly needs to be changed.

+1  A: 

This is the answer:

Response.TrySkipIisCustomErrors = true; 
Marek
Note that this affects IIS 7+ only.
Craig Stuntz
Yes, this works on IIS 7 and ASP.NET 3.5 only - fortunately, this is exactly my scenario.
Marek