Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resource not found instead of 413 request length exceeded

My page, when I try to upload a large file (over 10MB) displays me:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

My web.config has this

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

and

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

Why doesn't it redirect me to TooBig.html instead of displaying the afore-mentioned message?

Note

The default ASP.NET allows is 4MB, that's why I changed the maxRequestLength to 15000. (Changing it to 150000 does not make any difference at this point since I'm only testing with a maximum of 10MB)

like image 693
Rob Avatar asked Mar 14 '13 15:03

Rob


2 Answers

I have had that problem while moving to IIS7 with different size of files. But solution below worked for me that time. you should add those parts to your webconfig or appconfig file depends on scope you want.

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

For more information you may look at.

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

like image 198
Mahmut Ali ÖZKURAN Avatar answered Oct 24 '22 07:10

Mahmut Ali ÖZKURAN


Tested with .NET 4.x

It is not possible to handle this error in the web.config because it is too high level.

You can trap this error in the global.asax instead like this:

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
like image 22
George Filippakos Avatar answered Oct 24 '22 08:10

George Filippakos