Posts tagged ‘uploading of large files in ASP.net’

Setting up Web.config to allow uploading of large files in ASP.net C#

During the construction of an intranet application that allows users to upload documents and share information between users, I observed that when a user tries to upload files that are larger than 4 MB, the file is not uploaded, and he gets a HTTP 401.1 error.

The Problem

By default, Machine.config is configured to accept HTTP Requests upto 4096 KB (4 MB) and it is reflected in all your ASP.NET applications. We can change the Machine.config file directly, or you can change only theWeb.config file of the application(s) you want to.

The Solution

Open your Web.config file, and just below the <system.web> tag, add the following tag:

<httpRuntime 
executionTimeout="90" 
maxRequestLength="4096" 
useFullyQualifiedRedirectUrl="false" 
minFreeThreads="8" 
minLocalRequestFreeThreads="4" 
appRequestQueueLimit="100" 
enableVersionHeader="true"
/>

Now, just take a look at the maxRequestLength=”4096″ attribute of the <httpRuntime> tag.

You can change the value to some other value of your choice.

webconfig setting