In the September 2006 edition of
MSDN Magazine, Joe Stagner has written an excellent
article on different ways to handle file downloads in your ASP.NET applications. Stagner speaks to the issue of breaking up file downloads into manageable pieces in order to not overload memory as files are buffered when they travel from the ASP.NET worker process to the IIS process. Of particular interest, Stagner gives details on how to create a HTTP handler class to buffer download files and provide a mechanism for resuming downloads if the client disconnects in the middle of downloading. This HTTP handler class implements the IHTTPHandler interface which consists of the IsReusable property and the ProcessRequest method which is responsible for the custom HTTP handling code. Custom HTTP handlers can be enforced for a desired file type by mapping their extensions to a particular custom HTTP handler in the httpHandlers stanza in web.config. Here is an example taken from Joe Stagner's example (his HTTP handler class is in the Download namespace and is named ZIPHandler):
<httpHandlers>
<add verb="*" path="*.zip" type="Download.ZIPHandler,Download"/>
</httpHandlers>
HTTP handlers are especially powerful for .NET coders because they allow custom handlers to be written without having to create ISAPI extensions in C or C++.
The key to Joe Stagner's resuming download HTTP handler is the Entity Tag (ETag) header element used by the HTTP 1.1 protocol. This identifier provides a unique identifier for the session and allows the custom HTTP handler to resume the download. Check out all the details in Joe Stagner's article and code download.