user137348
user137348

Reputation: 10332

How to upload a file over 2MB

There is a limit, i cant upload a file over this limit.

When i set the maxRequestLength property over this limit i will get this error:

The value for the property 'maxRequestLength' is not valid. The error is: The value must be inside the range 0-2097151.

So how could i upload an image that is 5 MB big ? I can't use FTP access.

Upvotes: 1

Views: 4779

Answers (4)

Mike
Mike

Reputation: 276

You can change the max request length in the web. config file

<httpRuntime maxRequestLength="102400" />

Bear in mind that users will still be limited by bandwidth issues and may receive timeout errors.

You can put something like this in your Global.asax file to handle the errors in a more friendly manner:

protected void Application_Error(object sender, EventArgs e)
{
    Exception sourceException = Server.GetLastError().InnerException != null ? Server.GetLastError().InnerException : Server.GetLastError().GetBaseException();

    if (sourceException.Message.Equals("Maximum request length exceeded.") && Request.ContentType.Contains("multipart/form-data"))
    {
        HttpContext.Current.Server.ClearError();
        string path =//specify page to redirect to
        HttpContext.Current.Response.Redirect(path);/*in casini just get cannot connect page, but in iis get appropriate page*/ 
    }

}

Upvotes: 0

rossoft
rossoft

Reputation: 2182

The unit of maxRequestLength is KB. The default value is 4096 which means 4MB.

Just modify it to a value like 32000

Upvotes: 0

Doug R
Doug R

Reputation: 5779

The value is in kilobytes, so setting maxRequestLength to 8124 would allow 8MB uploads

Upvotes: 0

Tamas Czinege
Tamas Czinege

Reputation: 121414

It's in kilobytes, not bytes:

maxRequestLength on MSDN:

Indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users posting large files to the server. The size specified is in kilobytes. The default is 4096 KB (4 MB).

Upvotes: 8

Related Questions