Asp.net 未找到资源,而超出了413请求长度
当我尝试上载大文件(超过10MB)时,我的页面会显示: 您正在查找的资源已被删除,其名称为 已更改,或暂时不可用 我的web.config有以下内容Asp.net 未找到资源,而超出了413请求长度,asp.net,iis,httpfilecollection,Asp.net,Iis,Httpfilecollection,当我尝试上载大文件(超过10MB)时,我的页面会显示: 您正在查找的资源已被删除,其名称为 已更改,或暂时不可用 我的web.config有以下内容 <httpRuntime requestValidationMode="2.0" maxRequestLength="15000" /> 及 为什么它不将我重定向到TooBig.html而不是显示上述消息 注 ASP.NET允许的默认值是4MB,这就是我将maxRequestLength
<httpRuntime requestValidationMode="2.0" maxRequestLength="15000" />
及
为什么它不将我重定向到TooBig.html而不是显示上述消息
注
ASP.NET允许的默认值是4MB,这就是我将
maxRequestLength
更改为15000的原因。(此时将其更改为150000没有任何区别,因为我只使用最大10MB进行测试)我在使用不同大小的文件移动到IIS7时遇到了这个问题。但当时下面的解决方案对我有效。您应该根据需要的范围将这些部分添加到webconfig或appconfig文件中
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="524288000"/>
</requestFiltering>
</security>
</system.webServer>
有关更多信息,请参阅
使用.NET 4.x测试 无法在web.config中处理此错误,因为它的级别太高 您可以在global.asax中捕获此错误,如下所示:
Protected Sub Application_EndRequest(sender As Object, e As System.EventArgs)
Dim context As HttpContext = HttpContext.Current.ApplicationInstance.Context
If Not IsNothing(context) Then
If Not context.Response.StatusCode = HttpStatusCode.OK Then
'Detect file upload exceeded max length:
If context.Response.StatusCode = 404 And
context.Response.SubStatusCode = 13 Then
'clear the previous error page content:
context.Response.Clear()
'redirect to your custom upload error page:
context.Server.Transfer("~/error.aspx?code=404.13", False)
End If
End If
End If
End Sub
以下代码可能会有所帮助:
<httpRuntime enableVersionHeader="false" executionTimeout="300000" maxRequestLength="256000" requestValidationMode="2.0" requestLengthDiskThreshold="256000" />
可能的重复:我已经有了这么大的限制。谢谢,但这并不能解决问题。
<httpRuntime enableVersionHeader="false" executionTimeout="300000" maxRequestLength="256000" requestValidationMode="2.0" requestLengthDiskThreshold="256000" />