找不到资源而不是超过41​​3请求长度

时间:2013-03-14 15:33:47

标签: asp.net iis httpfilecollection

我的页面,当我尝试上传大文件(超过10MB)时,显示我:

  

您要查找的资源已被删除,名称已有   已更改,或暂时无法使用。

我的web.config有这个

<httpRuntime requestValidationMode="2.0" maxRequestLength="15000" />

<customErrors mode="RemoteOnly" defaultRedirect="~/Errorhandling.aspx">
      <error statusCode="404" redirect="~/NotFound.html" />
       <error statusCode="413" redirect="~/TooBig.html" />
</customErrors>

为什么不将我重定向到TooBig.html而不是显示上述消息?

注意

默认的ASP.NET允许为4MB,这就是我将maxRequestLength更改为15000的原因。(此时将其更改为150000没有任何区别,因为我只测试最大10MB)

3 个答案:

答案 0 :(得分:1)

我在使用不同大小的文件移动到IIS7时遇到了这个问题。但是下面的解决方案对我有用。您应该将这些部分添加到webconfig或appconfig文件中,具体取决于您想要的范围。

<system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="524288000"/>
            </requestFiltering>
        </security>
</system.webServer>

您可以查看更多信息。

http://www.webtrenches.com/post.cfm/iis7-file-upload-size-limits

答案 1 :(得分:1)

使用.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

答案 2 :(得分:1)

以下代码可能有所帮助:

<httpRuntime enableVersionHeader="false" executionTimeout="300000" maxRequestLength="256000" requestValidationMode="2.0" requestLengthDiskThreshold="256000" />