Share via


IIS Samples - ISAPI Chunked Transfer Encoding

This sample takes a file specified in a query string and sends it to the client in peices using chunked transfer encoding. If no query string is present, or if the query string does not identify a readable file, the sample returns a plain text page describing its usage.

warning Warning If you install this ISAPI extension on your server, make sure that you have configured IIS to restrict access to the virtual directory that contains the extension and the files you want to transmit. Also, set proper access control on the files in their physical folder. For more information, click Start, Help and Support, and search for Access Control.

important Important These samples are provided for educational purposes only. They are not intended to be used in a production environment, have not been tested in a production environment, and Microsoft does not provide technical support for them.

Sample Overview
Requirements
Location of the Source Code
Build and Install the Sample
Run the Sample
Sample Output
Helpdesk

Sample Overview

This sample is an ISAPI HTTP Extension DLL that demonstrates chunked transfer encoding. Chunked transfer encoding modifies the body of a message in order to transfer it as a series of chunks, each with its own size indicator. Unlike "normal" HTTP file transfer, chunked transfer does not need to specify (or even know) the transfer length in advance. There is no "Content-Length:" header transferred. For complete details about chunked transfer encoding, see section 3.6 titled Transfer Codings of the latest HTTP/1.1 specifications, available from https://www.w3.org/Protocols.

to top

Requirements

This sample requires the installation of the following software to function properly:

  • Windows XP Professional with IIS 5.1 installed or Windows .NET Server with IIS 6.0 installed.
  • Microsoft Internet Explorer (IE) version 4 and higher is required to browse to the sample.
to top

Location of the Source Code

IIS samples are included in the IIS Software Developer Kit (SDK). You can download the IIS SDK from Platform SDK Update. You can view the SDK at MSDN Online. In the table of contents at MSDN Online, click Web Development, Server Technologies, Internet Information Services (IIS), SDK Documentation, Internet Information Services, Samples.

The following source code files are required for this sample:

File Description
CTETest.sln CTETest Visual Studio .NET solution file, required to build this sample in Visual Studio .NET.
CTETest.vcproj CTETest Visual Studio .NET C Project file, required to build this sample in Visual Studio .NET.
CTETest.dsp, CTETest.dsw CTETest Visual Studio Version 6 project files, required to build this sample in Visual Studio Version 6.
CTE_Enc.c, CTETest.c CTETest source modules containing the code that implements the extension.
CTETest.def CTETest.dll definition containing code for creating the extension DLL.
CTETest.h CTETest header file containing commonly called routines.
MAKEFILE CTETest makefile for command line compilation
to top

Build and Install the Sample

To build this sample using the Visual C++ IDE, the following steps must be performed:

  1. Open the solution (VS.NET) or desktop (VS6) file to open the project.
  2. Click Build to create the DLL.

To build and run this sample without using the Visual C++ IDE, the following steps must be performed:

  1. Type NMAKE All from the command line. For example, if your sample files are located in a folder called C:\MySamples, type the following at the command line:
    cd /d c:\MySamples
    NMAKE All
    

To install this sample, the following steps must be performed:

  1. Copy CTETest.dll to a physical folder on your computer. For example, create a folder called C:\Samples and copy CTETest.dll to that folder.
  2. Create a virtual directory that maps to the physical folder containing your files. To create a virtual directory, open the Internet Information Services (IIS) Manager by clicking Start, Run, type inetmgr in the text box and click OK. Right-click the Web site where you want to create a virtual directory, click New, and click Virtual Directory. In the Alias text box, type the name you want for your virtual directory, for example, CTETest. In the Directory text box, type the path to the folder that contains your files.
  3. Configure strong security on your new virtual directory. Right-click the virtual directory name, click Properties, and click the Directory Security tab. Press F1 for tips on securing your virtual directory.
  4. Use Windows Explorer to set restricted access control on the sample .dll file in its physical folder. For more information, click Start, Help and Support, and search for Access Control.
to top

Run the Sample

In order to run this sample, follow the instructions listed below:

  1. Copy a file that you want to transfer to any physical folder on your computer, provided that the folder is mapped to a virtual directory. For example, if you have an image file called sample.gif, copy it to the same folder that contains CTETest.dll since you already mapped that folder to a virtual directory.
  2. In Internet Explorer (IE), browse to CTETest.dll as if it were a Web file, and pass in a query string containing the name of a file to transfer as well as the chunk size. For example, if the file you want to transfer is called sample.gif, and it is in the same folder as CTETest.dll, and that folder is mapped to a virtual directory called CTETest, type the following in the address bar of IE:
    https://localhost/CTETest/CTETest.dll?file=/CTETest/sample.gif+chunksize=1024
    
to top

Sample Output

After performing step 2 in Run the Sample, you should see the file that you listed in your query string. If the file is large, you may see it appear in chunks until the whole file is displayed.

to top

Help Desk

If here you do not find answers to your questions, visit the Microsoft Help and Support Web site.

Problem Possible Solution
When building the dll, C++ returns a permissions error. Once you have called the dll from your web page, your system considers it a loaded dll. You must unload it to build it again, either by unloading the ASP application or deleting the dll from system32\dllcache.
When browsing to the dll, IE gives you a permissions error. The folder and virtual directory must have Execute permissions set on them.
to top