Monday, February 21, 2011

Problem uploading large files in ASP.NET

Impact: Application throws System.Web.HttpException: Maximum request length exceeded exception.

Solution: This is the most common problem that most of the new developers face while developing ASP.NET applications which require files to be uploaded to the server. ASP.NET restricts the size of file being uploaded to a maximum of 4MB, however you can change the default value by following the steps mentioned below.
  1. Open you application's web.config file.
  2. Find a node called <httpRuntime>, if the node doesn't exist then create one inside <system.web> nodes.
  3. Change the value of attribute maxRequestLength to the file size you want in KB. 
  4. You may also have to change the value of attribute executionTimeout, this value is in seconds.
Example:

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