Pages

Tuesday, July 6, 2010

Huge File Uploads in ASP.NET

After a month and half, bosome time to keep this going.

There was an issue happening repeatedly, when we were trying to upload an image file with size 5MB through an File Upload Control in ASP.NET application.

Uploading a large file with File Upload Control gets tricky. The maximum default size is limited to 4MB by .NET framework, since some attackers may find this easier to upload large files which inturn consume huge server resources.

Increasing the Maximum Upload Size

The 4MB default is set in machine.config.

<system.web>
<httpRuntime executionTimeout="110" maxRequestLength="20000" />
</system.web>

But you can override it in you web.config. For example, to expand the upload limit to 20MB, you'd do this:

<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>

Hope this solution might help to solve your problems. Please pass in your valuable feedbacks or doubts here.