ASP.NET File upload observations

For a company I was asked to find out why they were having trouble uploading files through a slower (< ISDN) connection. They were experiencing Page Not Found errors for files larger than 1 MB. When I explored this problem I found out the following:

  • ASP.NET loads the entire uploaded file into it’s process space. It is possible (although not easy) to create a custom HttpModule that handles uploads in smaller chunks. See first link below for an interesting discussion.) Posted a comment on Simon Fell’s weblog for a post on this matter.
  • When ASP.NET reaches the (default) threshold of 60% of consumed server memory, it will recycle itself.
  • The maximum size of an uploaded file is 4MB by default. You can change this limit by setting the maxRequestLength of the element in the web.config. Preferably you use  to limit this changed size to the single page that handles the upload. When a upload contains more than the maxRequestLength in bytes, ASP.NET will show a Page Not Found or DNS Error page. It does not give you any change to intercept this event or error.
  • It is possible to check the total amount of bytes that will be uploaded before the files are actually streamed to the server. Use the HttpApplication.BeginRequest event from within global.asax or create a custom HttpModule. Simple enough. The code looks like this:

public static long maxRequestLength = 1024000;

private void Global_BeginRequest(object sender, System.EventArgs e)
   long requestLength = HttpContext.Current.Request.ContentLength;
   if (requestLength > Global.maxRequestLength)
    // Normally a rewrite of the path would be used.
    // However, the current request will be handled by doing so, resulting   
    // in the upload of the file(s). Hence a Server.Transfer or 
    // Response.Redirect. The latter will make you loose all
context information of the original call.


Ideally you would retrieve the maxRequestLength variable from the web.config file.

  • IIS 4.0+ has a connection timeout of 900 seconds (default). Use the MMC Snapin for IIS (Properties for website, Web Site tab) or MetaEdit to change this value.
  • Internet Explorer has a timeout of 60 minutes for IE5.0+ for receiving responses from the server.
  • ASP.NET has a execution timeout value. If a page executes longer than this timeout value, the request is preempted. Default value is 90 seconds, just as in ASP.
  • If there are pending requests and ASP.NET does not generate a response within 180 seconds it will assume it is deadlocked and will recycle the aspnet_wp.exe worker process!

Hope this is of any use to anyone. Some interesting links in this matter:


BTW, as it turned out they were only experiencing the problems from behind their own firewall. All settings as mentioned above weren’t the actual problem. It was the firewall.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s