Large File Uploading in ASP.NET
I posted this to the ASP.NET forums back in November of 2002, and, too much of my dismay, still is an issue and people are still having problems figuring this out. I don't really know how many times I've helped people with this problem, and just recently I had to do the same. So, for my own personal reference (mainly), and to share the information, I decided to re-post it in my blog...
First the good...
To upload large files, and
not receive the DNS Error or the page stopping while
uploading, we found several settings between the
machine.config and the web.config files that you need to
modify. There are specifically 3 places, 2 of which can be
overwritten in your web.config file.
In your
web.config, add a line under your system.web
<httpRuntime executionTimeout="54000"
maxRequestLength="512000" /> where execution timeout is
in seconds, and maxRequestLength is in KB.
executionTimeout, is basically the amount of time a thread
will continue to run, and accept data by IIS/.NET.
maxRequestLength, is the total amount of data that can be
sent through HTTP Post to the server. The default is 4MB
(4096)...and is generally set low so that your server will
not be overwhelmed by possible DoS attacks.
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.
These 3 changes
will allow you to successfully upload large files.
Now...the bad...
Memory
deallocation is a major issue, that has no current
solution. Whenever you upload files via HTTP Post, the
file is stored in the memory of the aspnet_wp.exe process,
and never deallocates completely (if your lucky a few MB
gets released). One of the config settings for .NET
processes, allows them to utilize 60% of physical memory
on the server, at which point the process is recycled and
all execution is stopped. Whenever a new upload is
started, though, some memory is de-allocated, but not
enough compared to memory that was used in prior uploads.
Microsoft is aware of this problem, and has
assured us that it will be fixed with some upcoming
releases of the .NET framework. Some solutions that they
suggested to us, was to use Classic ASP, Third Party
Components, or Custom Built ISAPI filters. Because of our
solution we were using this in, we could do none of the
three, so we topped the server out at 2GB of RAM. This has
provided us with some breathing room if several people
start uploading huge files, and gives us enough time to
restart IIS if we start nearing 1.3GB of RAM being used by
aspnet_wp.exe.