ASP.NET MVC 404处理和IIS7&LT; httpErrors&GT; [英] ASP.NET MVC 404 handling and IIS7 <httpErrors>
问题描述
美好的一天!
我用的策略来处理这样的404错误:<一href=\"http://stackoverflow.com/questions/3545906/error-handling-for-asp-net-mvc-2-and-iis-7-0\">http://stackoverflow.com/questions/3545906/error-handling-for-asp-net-mvc-2-and-iis-7-0或本:<一href=\"http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404s-in-asp-net-mvc/620559#620559\">http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404s-in-asp-net-mvc/620559#620559
总之:我处理404在的Global.asax
例外,不添加任何路由规则,如果异常是404我渲染错误讯息专用控制器\\行动<。 / p>
在IIS6它与ASP.NET通配符映射。在IIS7集成模式我需要添加以下到的Web.config
(其中 /故障/ HttpError404
是我的404页的动作):
&LT; httpErrors&GT;
&LT;清除状态code =403子状态code = - 1/&GT;
&LT;清除状态code =404子状态code = - 1/&GT;
&LT;错误状态code =404prefixLanguageFilePath =PATH =/故障/ HttpError404responseMode =ExecuteURL/&GT;
&LT;错误状态code =403prefixLanguageFilePath =PATH =/故障/ HttpError403responseMode =ExecuteURL/&GT;
&LT; / httpErrors&GT;
为什么呢?路由的工作方式不同在IIS集成模式和IIS6通配符映射?
在此先感谢!
更新:
根据我的测试,似乎我的错误处理的作品和我的404的动作呈现,但似乎IIS看到404响应code(我设定编程在我的404行动),并用默认的错误取代我的网页。
当我设置&LT; httpErrors&GT;
我得到了404页两支安打:一个来自异常处理的Global.asax
和一个从IIS。
可这是原因?
看来我已经在的Web.config
设置固定的:
&LT; httpErrors existingResponse =直通/&GT;
Good day!
I use strategy to handle 404 errors like this: http://stackoverflow.com/questions/3545906/error-handling-for-asp-net-mvc-2-and-iis-7-0 or this: http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404s-in-asp-net-mvc/620559#620559
In short: I handle 404 as exception in Global.asax
without adding any routing rules, if the exception is 404 I render special controller\action with error message.
On IIS6 it works with ASP.NET wildcard mapping. On IIS7 in integrated mode I need to add the following to the Web.config
(where /error/HttpError404
is my action with 404 page):
<httpErrors>
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/error/HttpError404" responseMode="ExecuteURL" />
<error statusCode="403" prefixLanguageFilePath="" path="/error/HttpError403" responseMode="ExecuteURL" />
</httpErrors>
Why? Routing works differently on IIS integrated mode and IIS6 wildcard mapping?
Thanks in advance!
UPDATE: According to my tests it seems that my error handling works and my 404 action is rendered, but it seems that IIS sees 404 response code (which I set programmatically in my 404 action) and replace my page with default errors.
When I set <httpErrors>
I got two hits for 404 page: one from exception handling in Global.asax
and one from IIS.
Can this be the cause?
It seems I have fixed it by setting in Web.config
:
<httpErrors existingResponse="PassThrough" />
这篇关于ASP.NET MVC 404处理和IIS7&LT; httpErrors&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!