Good day!
美好的一天!
I use strategy to handle 404 errors like this: Error handling for ASP.NET MVC 2 and IIS 7.0 or this: How can I properly handle 404 in ASP.NET MVC?
我使用策略来处理404错误:ASP的错误处理。NET MVC 2和IIS 7.0或者这个:我如何在ASP中正确地处理404。净MVC吗?
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.
简而言之:我处理404作为全局异常。没有添加任何路由规则的asax,如果异常是404,我将呈现带有错误消息的特殊控制器\操作。
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):
在IIS6上,它与ASP一起工作。净通配符映射。在IIS7的集成模式下,我需要在Web上添加以下内容。配置(where /error/HttpError404是我的操作,带有404页面):
<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?
为什么?在IIS集成模式和IIS6通配符映射上,路由的工作方式不同?
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.
更新:根据我的测试,似乎我的错误处理和404操作都有效,但IIS似乎看到了404响应代码(我在404操作中以编程方式设置),并将页面替换为默认错误。
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?
这是原因吗?
1 个解决方案
#1
11
It seems I have fixed it by setting in Web.config
:
好像是我在Web.config中设置的。
<httpErrors existingResponse="PassThrough" />
#1
11
It seems I have fixed it by setting in Web.config
:
好像是我在Web.config中设置的。
<httpErrors existingResponse="PassThrough" />