Uploading large files using asp.net and IIS6.0

Hi,

We all must have obviously uploaded files somewhere or the other. Even in the websites that we create using ASP.NET, we might have to put the asp:fileupload control to facilitate file upload feature.

While developing websites or web applications, we might come across requirements that specify: Allow users to upload large files (file size typically greater than 10MB)

In such a case, only putting a file upload control in our website isn’t sufficient. The reason for this is, the upload filesize limit is set to 4MB by default in ASP.NET.

To allow large files to be uploaded in our website, we need to make a few configuration changes. The “httpRuntime” tag in the web.config file is where we need to change the file size limit.

The <httpRuntime> tag has an attribute “maxRequestLength” whose value is specified in “KiloBytes“. Also, increase the value of the “executionTimeout” attribute of the same tag so that the uploading doesn’t time out before the entire file has been uploaded.

The tag would look something like this:

<httpRuntime maxRequestLength=”2097152″ executionTimeout=”9999999″ />

This would allow for files upto 2GB to be uploaded. I have discussed this scenario more clearly in this post

But in some cases, we might also need to make changes at IIS side. We need to increase the values of some attributes in the Metabase file of IIS.

The Metabase.xml file is the one we need to modify to allow large files to be uploaded. This file is located at

C:\Windows\System32\inetsrv\

location.

But this file is by default in Read-Only mode and this cannot be changed by right-clicking the file and changing the mode. It has to be made editable in another way.

Procedure to make Metabse.xml editable: (FOR IIS 6.0 only)

  1. Open IIS manager (open Run -> type ‘inetmgr’ -> press enter)
  2. Right-click on the local computer name. Click on Properties.
  3. Enable the Checkbox that reads “Enable Direct Metabase Edit”.
  4. Click on Apply. Then OK.

The above procedure is only for IIS 6.0 as in IIS 7.0 and above, microsoft has removed the Enable Direct Metabase Edit option. I’ll come back to that later.

So, after the Metabase.xml file has been made editable, navigate to the file location. Its better to take a back up of the file before modifying it (just to be on the safe side :-)). The attributes to be modified are:

  1. AspBufferingLimit
  2. AspMaxRequestEntityAllowed

The values of both the attributes are specified in “BYTES“. Be careful about the units in which the values of these attributes are specified. The ones in IIS take values in BYTES. The one in the web.config file takes values in KILOBYTES.

Modify the values in the above attributes and save the file. Now your website should allow files upto 49MB to be uploaded. It is said that files upto even 100MB can be uploaded but I could never accomplish that! 😦 The maximum filesize my website accepted was 49MB. If anyone can come up with a solution to this, please make sure you share it 🙂

Another thing I would like to add to this is that if you are using web service to upload the file to an external content database like SharePoint, then you will have to change the binding configuration of the services as well.

When we add a service reference to our website, the corresponding service inding information is added to the web.config file in the website. To allow large files to be uploaded, the attributes in the binding information to be modified are:

  1. maxBufferSize
  2. maxReceiveMessageSize
  3. maxBufferPoolSize
  4. maxDepth
  5. maxStringContentLength
  6. maxArrayLength

Also, make sure you increase the timeout values here as well.

Please feel free to comment or make any corrections if required anywhere 🙂

Hope this helps 🙂

Advertisements

About Amogh Natu

Technology enthusiast, Associate Consultant @ Microsoft, music lover, love my guitar, Microsoft.NET, ASP.NET, C#.NET Professional.
This entry was posted in ASP.NET, CodeProject, General, IIS and tagged , , , , , , , , , , , . Bookmark the permalink.

Your comments or opinions.....

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s