Large Uploads in ASP.NET

New in V4


FileUp's ISAPI Filter

FileUp's ISAPI filter is used under ASP.NET to overcome ASP.NET's inefficient memory utilization and to allow accurate progress indication. The ISAPI filter significantly improves the performance of very large uploads. With the filter, FileUp can upload up to 4 gigabytes. Note that most browsers support uploads of up to 2 GB; larger uploads must be generated by a client-side control that can handle very large transfers. The ISAPI filter intercepts an upload request, reads all the data, and writes it to a temp file chunk by chunk, before sending it to ASP.NET.

For performance reasons, the ISAPI filter will not intercept all ASP.NET requests; only those for a file with the extension .uplx will be handled by the filter. Files with the extension .aspx will not be processed by the filter, and will be sent directly to ASP.NET. This prevents burdening the server with unnecessary use of the ISAPI filter. So, to use the filter, name your ASP scripts FileName.uplx.

Note: Under ASP.NET, FileUp's progress indicator is handled by the ISAPI filter. So, to display accurate progress indication, upload to a file with the .uplx extension.

FileUp's automatic installation package will install the ISAPI filter in IIS, and the script mapping for the upl extension. You can re-install the filter manually (if, for example, you move FileUp to a different machine), as follows:

Note: FileUp's ISAPI filter must be installed at the machine level, not the Web site or Web application level.
  1. Open IIS, right-click the machine name icon, and select Properties.


  2. Select the Internet Information Services tab.


  3. From the Master Properties drop-down list, select WWW Service, and click Edit.


  4. Select the ISAPI Filters tab.


  5. Click Add.


  6. In the Filter Properties dialog box, enter the filter name FileUp, browse to FileUpIsapi.dll, and click Ok.


  7. Restart IIS to load the filter. Right-click the machine name icon, select Restart IIS..., select Restart Internet Services from the drop-down list, and click Ok.

Note: If you are testing FileUp with a beta release of IIS 6.0 on Windows .NET Server, the Web site must be configured to run in IIS 5 mode. The filter cannot be installed properly if the site is in IIS 6 mode. To run IIS 6 in IIS 5 mode:
  1. In IIS, right-click the Web site, and open Properties.
  2. Select the Service tab.
  3. Check Run Web service in IIS 5.0 isolation mode.

For information on mapping the uplx extension, see Allowing ASP.NET to Process Files with the .uplx Extension.

Top


The ISAPI Filter Temp Directory

The ISAPI filter caches request data before it is processed by ASP.NET. The location of the cache files can be configured in the Windows registry. By default, the cache location is the system's default directory for cached files, which is determined by the system environment variable TEMP. To set a different ISAPI filter temp directory:

  1. Open the Start menu, and select Run.
  2. Enter regedit and click Ok.
  3. Open HKEY_LOCAL_MACHINE\SOFTWARE\Software Artisans\SA-FileUp\Parameters.
  4. Right-click IsapiTempDir and select Modify.
  5. In Value Data, enter the path and folder name.
  6. To reset IIS, at the command prompt enter iisreset. Note: The new IsapiTempDir setting will not take effect until you reset IIS.
Note:   To change the system's default directory for cached files, reset the TEMP environment variable, as follows:
  • Open the Control Panel.
  • Select System.
  • Select the Advanced tab.
  • Click Environment variables...
  • Select TEMP from the System Variables list.
  • Click Edit.
  • Enter a new Variable Value, and click Ok.

Top


The ISAPI Filter and the UseMemory Property

FileUp's UseMemory property allows you to keep uploaded data in memory until it is saved. The ISAPI filter reads the whole upload request and writes it to temporary files before the request is processed by the ASP.NET page on the server. If you set UseMemory in the ASP.NET page, the property will have no effect because the page is processed after the ISAPI filter writes the temp files. To set UseMemory when using the ISAPI filter, include the property in the request query string.

The following lines are from a client-side upload script. The form's onSubmit event is set to trigger the startupload function. This function adds UseMemory=True to the query string so that the ISAPI filter receives this information and does not cache the request.

	<HTML>
	<HEAD>
	...
	<SCRIPT Language="JavaScript">
	/* 
	The startupload function adds UseMemory=True to the query string.  The 
	ISAPI filter will read the query string, and instead of creating 
	temporary files, will store the uploaded file(s) in memory until 
	submitting them to the ASP.NET response page.
	*/
	function startupload() {
		document.theForm.action="formresp.uplx?usememory=true";
		}
	</script>
	</HEAD>
	<BODY>
	...
	<TABLE ALIGN=center width="550" border=0>
	<FORM onSubmit="startupload();" name="theForm" ACTION="formresp.uplx" 
	ENCTYPE="MULTIPART/FORM-DATA" METHOD="POST">
	<TR>
		<TD ALIGN="RIGHT" VALIGN="TOP">Enter Filename:</TD>
		<TD ALIGN="LEFT"><INPUT TYPE="FILE" NAME="myFile"><BR>
		<I>Click "Browse" to select a file to upload</I></TD>
	</TR>
	<TR>
		<TD ALIGN="RIGHT"> </TD>
		<TD ALIGN="LEFT"><INPUT TYPE="submit" NAME="SUB1" VALUE="Upload File"></TD>
	</TR>
	</TABLE>
	</FORM>
	...

Top


Allowing ASP.NET to Process Files with the .uplx Extension

FileUp's ISAPI filter will intercept requests for .uplx files. FileUp's automatic installation adds the appropriate script map to IIS so that requests for .uplx files are handled by the filter and then forwarded to ASP.NET. If you reinstall FileUp manually (if, for example, you move FileUp to a different server), you will need to add the following IIS script map:

Note: Under ASP.NET, FileUp's progress indicator is handled by the ISAPI filter. So, to display accurate progress indication, upload to a file with the .uplx extension.

Top


MaxClientRequestBuffer

The IIS parameter MaxClientRequestBuffer sets a maximum size for the first chunk of a request. The first chunk will usually contain only a request's line and header fields, which includes all data in a request that is not part of the request's entity body. The default value of MaxClientRequestBuffer is 128 KB.

FileUp's ISAPI filter creates a new request and sends the entire request to ASP or ASP.NET as one chunk. When an upload contains many files, the ISAPI filter request may exceed the default value of MaxClientRequestBuffer and IIS might reject the request. To prevent this, add a MaxClientRequestBuffer key to the registry and set it to an appropriate value. Many factors can affect the size of the ISAPI filter request, but it will usually be around 128 KB per 600 uploaded files. To add MaxClientRequestBuffer to the registry and set it to a new value:

  1. Open the Start menu and select Run...


  2. Enter regedit and click Ok.


  3. Open the folder HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\.


  4. From the Edit menu select New -> DWORD Value.


  5. Right-click the new key and rename it MaxClientRequestBuffer.


  6. Double-click MaxClientRequestBuffer An Edit DWORD Value dialog will open.


  7. Under Base select Decimal.


  8. In the Value Data field, enter a buffer size in kilobytes.

Top


.NET Settings

In the .NET configuration file for your Web application - web.config or machine.config - there are several attributes that can affect the performance of large uploads. To set these attributes at the machine level, modify machine.config (located in C:\WINNT\Microsoft.NET\Framework\v1.0.3705\CONFIG). To set the attributes at the application level, modify your application's web.config file.

You will find the following values in the httpRuntime node of machine.config:

The following attribute is in the processModel node of machine.config:

Top


Copyright © 2002 SoftArtisans, Inc. All rights reserved.