如何配置IIS服务于我和我的自定义内容404响应? [英] How to configure IIS to serve my 404 response with my custom content?
问题描述
此问题是关系到<一个href=\"http://stackoverflow.com/questions/2547582/asp-net-mvc-how-to-serve-content-while-returning-status-$c$c-404\">this,希望更好的措辞。
This question is related to this, hopefully better phrased.
我想从ASP.NET MVC服务自定义的404页。我有路由处理和所有的基础设施设置,以确保不存在路由通过单个动作处理:
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");
}
问题:IIS服务回自己的内容(一些predefined消息),当我返回内容之前设置Response.Status code至404
Problem: IIS serves back its own content (some predefined message) when I set Response.StatusCode to 404 before returning the content.
在VS开发Web服务器,这工作按预期 - HTTP响应状态code是404,而我的内容(NOTFOUND视图)供应
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.
我相信,当IIS处理管道看到应用程序返回404,它只是替换了自己的整个响应。
I believe that when the IIS processing pipeline sees that the application returns 404, it simply replaces the whole response with its own.
什么设置在IIS影响这种行为?
我没有访问IIS安装,所以我不能调查这 - 不过,我可以要求托管服务提供商,调整配置的我,如果我确切地知道需要改变什么
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.
推荐答案
<一个href=\"http://stackoverflow.com/questions/2376739/asp-net-mvc-custom-error-page-status$c$c-404-throws-a-500/2376857#2376857\">This答案是:
Response.TrySkipIisCustomErrors = true;
这篇关于如何配置IIS服务于我和我的自定义内容404响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!