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

五迷三道 提交于 2019-12-19 09:49:08

问题


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:


This is the answer:

Response.TrySkipIisCustomErrors = true; 


来源:https://stackoverflow.com/questions/2551959/how-to-configure-iis-to-serve-my-404-response-with-my-custom-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!