How to configure IIS to serve my 404 response with my custom content?
Posted
by Marek
on Stack Overflow
See other posts from Stack Overflow
or by Marek
Published on 2010-03-31T10:08:31Z
Indexed on
2010/03/31
10:13 UTC
Read the original article
Hit count: 257
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.
© Stack Overflow or respective owner