【发布时间】:2012-07-05 14:51:01
【问题描述】:
我有一个简单的 ASP.NET MVC 3 网站托管在 IIS 7.0 中,但在显示 404.13的自定义 http 错误页面时遇到了困难> http 状态码。
我的 Web.Config
中有以下配置<system.web>
<httpRuntime maxRequestLength="2048"/>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear/>
<error statusCode="404" subStatusCode="-1" path="/home/showerror" responseMode="ExecuteURL" />
<error statusCode="404" subStatusCode="13" path="/home/showerror" responseMode="ExecuteURL" />
</httpErrors>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1048576"/>
</requestFiltering>
</security>
</system.webServer>
当我导航到一个不存在的页面时,我的错误页面会正确呈现。但是,如果我上传一个大于 1MB 的文件,我会看到一个空的 404 响应。该 url 永远不会被执行。如果我将 responseMode 更改为 Redirect 则用户被正确重定向。
【问题讨论】:
-
@DarinDimitrov 该问题使用 responseMode=Redirect,这是一个不同的问题,它不是重复的。
-
它使用重定向,因为 ExecuteURL 不适用于 404.13,如重复答案中所述。
-
@DarinDimitrov 在那篇文章中,答案谈到了清除此 Application_Error 方法中的错误,在我的例子中,当发生 404.13 时,永远不会调用此方法
-
请仔细阅读副本,我引用:
For uploaded files with size between maxRequestLength and maxAllowedContentLength IIS7 will throw an HttpException with HttpCode 500 and message text "Maximum request length exceeded"...。然后:For uploaded files with size bigger than maxAllowedContentLength IIS7 will display a detailed error page with error code 404 and subStatusCode 13。我猜你陷入了第二种情况,这就是为什么 Application_Error 永远不会被调用。如果您在它有机会访问您的应用程序之前远远超出此限制,则 IIS 会终止该请求。
标签: asp.net-mvc-3 iis-7