large file uploads in asp.net -part 1

Uploading large files in asp.net requires a bit of configuration changes and met with certain challenges with different versions of asp.net(I would say asp.net 2.0 and below). In this blog post I am trying to address some issues covering the large file upload in asp.net on IIS6/IIS7.x .

As the topic can get a bit complex (If you are dealing with really large uploads e.g above couple of hundred MBs),i have divided the posts into three different posts.

  • Part 1- Common issues with upload process - This is covered in this post.Some of the issues are already covered

 https://blogs.msdn.com/b/prashant_upadhyay/archive/2011/07/13/large-file-upload-issue-in-asp-net.aspx

https://weblogs.asp.net/jgalloway/archive/2008/01/08/large-file-uploads-in-asp-net.aspx

First of all,let’s discuss the issues surrounding the large file uploads using the built in file upload control

  • 401 error because of the default 4 MB size limit to be uploaded

  • may receive DNS error or page stopping while uploading

  • in IIS7,30 MB contentlength limit

  • Memory usage of the aspnet_wp.exe/w3wp.exe process.You may get OutOfMemoryException

  • File get uploaded to asp.net temporary files first(that’s in system dir )

  • Unable track the file upload progress easily

  • Problems with ExecutionTimeOut

  • 401 error- 4 MB size limit

        The 4MB default is set in machine.config, but you can override it in you web.config. For instance, to enable the upload limit to 20MB, you can do this:

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

  • DNS error or page stopping while uploading

    In your machine.config, modify responseDeadlockInterval to equal the same amount of time for executionTimeout. responseDeadlockInterval, is basically the amount of time that the Client's browser and Server will continue to communicate. Every several minutes or so, the server polls the client, asking if they have any more information to send, if they do not receive anything back after several times, then the server stops the current thread and all communication is stopped. This is the cause of the DNS Error you may see sometimes. 

This is covered in this kb 817321 article

  • In IIS7,30 MB contentlength limit

    This can be increased in the web.config file as shown below

<system.webServer>

           <security>
                   <requestFiltering>
                           <requestLimits maxAllowedContentLength="300000000" />
                   </requestFiltering>
           </security>
    </system.webServer>
Can use IIS manager UI as shown below

image

  • OutOfMemoryException

        You may get an OutOfMemoryException while uploading large files(files of few 100 MBs).The problem was with the implementation of asp.net (2.0 and below) file upload process.It loads all the file contents to memory as a byte array and then process.This may cause heap fragmentation 32 bit process and less memory available .You cannot avoid this error if you are using FileUpload control.I will get into more details on this and how to avoid this

  • Uploaded file get stored in the temporary asp.net folder first

whenever a file is getting uploaded using the file upload control or you are referring the Request.Files property,it uses a class internally to store the files to the asp.net temperory folder.This again an implementation detail and this will cause problems if you are concurrently uploading a large number of files to application.

  • Tracking the file upload progress

    FileUpload control’s save as method actually saves the file to the specified location from the aforementioned temporary location.Also if you are accessing the Request.Files property,the file is already uploaded to the temp folder.

  

t I will try to explore the last 3 points in the next set of posts