开发者

How to configure IIS to serve my 404 response with my custom content?

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 hand开发者_开发技巧ler 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.


This is the answer:

Response.TrySkipIisCustomErrors = true; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜