IIS Samples - ISAPI KeepAlive With Threads

This sample demonstrates how to maintain a Keep-Alive connection while using worker threads in an ISAPI dll.

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

The way that this dll maintains the connection is in the following line from WorkerFunction:

dwState = HSE_STATUS_SUCCESS_AND_KEEP_CONN;
pECB->ServerSupportFunction(pECB->ConnID, HSE_REQ_DONE_WITH_SESSION, &dwState, NULL, 0);

The passing of dwState is what tells IIS to keep the connection open.

A thread pool is used because if the thread that makes the above call to server support function exits or is terminated, the connection will be closed by IIS. Using a thread pool avoids this.

This dll creates a number of system objects, which are not deallocated. The presumption is that this dll will remain loaded until the INETINFO.EXE process terminates; at which point these objects will be released by the operating system. However, if the WWW service is stopped and restarted without the INETINFO.EXE process ending, these objects will remain allocated, and new ones will be created when the dll is reloaded. If it is desired to implement this sample code in a production environment, code to deallocate these objects should be added in DllMain or TerminateExtension.

to top

 

Requirements

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

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
KeepAliveP.sln KeepAliveP Visual Studio .NET solution file, required to build this sample in Visual Studio .NET.
KeepAliveP.vcproj KeepAliveP Visual Studio .NET C Project file, required to build this sample in Visual Studio .NET.
KeepAliveP.dsp, KeepAliveP.dsw KeepAliveP Visual Studio 6.0 project files, required to build this sample in Visual Studio Version 6.
KeepAliveP.c, ThreadPool.c KeepAliveP source modules containing the code that implements the sample.
KeepAliveP.def KeepAliveP.dll definition containing code for creating the sample.
ThreadPool.h KeepAliveP header file containing commonly called routines.
MAKEFILE KeepAliveP 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 KeepAliveP.dll to a physical folder on your computer. For example, create a folder called C:\Samples and copy KeepALiveP.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 on 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, KeepAliveP. 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. Browse to your sample Web files in Internet Explorer (IE). For example, if your files are in a virtual directory called KeepAliveP, type http://localhost/KeepAliveP/KeepAliveP.dll in the Address bar of IE.
to top

 

Sample Output

There is no output for this sample.

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 browsing to the ASP page, IE returns HTTP 404 - File not found Verify that you have created a virtual directory of the same name you are typing in the Address box of IE....
When building the dll, C++ or VB returns the 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 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

© 1997-2002 Microsoft Corporation. All rights reserved.