IIS is overriding my response content, if i manually set the Response.StatusCode

Posted by Pure.Krome on Server Fault See other posts from Server Fault or by Pure.Krome
Published on 2010-03-18T06:51:58Z Indexed on 2010/03/18 7:01 UTC
Read the original article Hit count: 459

Hi Folks,

Problem

when i manually set the HTTP Status of my Response stream to .. say 404 or 503, IIS renders up the stock IIS content/view, instead of my custom view.

When I do this with the Web Development Server (aka. Casinni), it works correctly (ie. my content is displayed and the response.statuscode == my entered data.

Is there anyway I can override this behaviour?

How To Replicate

Make a default ASP.NET MVC1 web app. Add the following route

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default",
        "{*catchall}",
        new { controller = "Home", action = "Index" }
        );

}

Now replace the the HomeController's Index method with...

[HandleError]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        Response.StatusCode = 404;
        return View();
    }
}

:( Please help!

© Server Fault or respective owner

Related posts about iis7.5

Related posts about windows-server-2008