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.
First of all,let’s discuss the issues surrounding the large file uploads using the built in file upload control
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>
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
This can be increased in the web.config file as shown below
<security> <requestFiltering> <requestLimits maxAllowedContentLength="300000000" /> </requestFiltering> </security> </system.webServer>Can use IIS manager UI as shown below
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
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.
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