SAMPLE: Sharing Data Between ISAPI Filters and ISAPI Extensions (194706)



The information in this article applies to:

  • Microsoft Internet Server Application Programming Interface (API)

This article was previously published under Q194706

SUMMARY

There are situations where maintaining state information (or sharing data) between an ISAPI Filter and an ISAPI Extension is desirable. One example is capturing the Username and Password during the authentication notification of an ISAPI Filter to generate application-specific information, which will then later be used within an ISAPI Extension.

The simplest mechanism to handle this sort is adding a new header into the request headers within the filter before invoking the extension is invoked (you can do this during the pre-proc header notification). However, this technique is limited by both size considerations (it wouldn't advisable to add a 100KB header entry--the result would be significant performance hit) and the fact that only ASCII-based information can be exchanged.

There are many other techniques that can be used to pass information from a filter to an extension. This sample will use the Win32 Shared Memory mechanism to pass information from a filter to an extension.

Smemfilt.exe is a sample that contains the necessary files for a Visual C++ 6.0 project for an ISAPI filter. Smemext.exe contains the files for a Visual C++ 6.0 project for an ISAPI extension. Both use the same SMemBlock class (SMemBlock.h/.cpp), which is included in each self-extracting executable.

This sample assumes the reader is familiar with C++ classes and use of both Win32 File Mapping object and named synchronization object (Mutex). For more information on these objects, please refer to the Visual C++ Online documentation.

MORE INFORMATION

The following files are available for download from the Microsoft Download Center:
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. The idea behind this sample is that the filter will create a shared memory pool, which contains a pre-determined number of memory "blocks." These blocks will then be checked out and checked in to the pool. The filter will check out a block (if one is available) and write some data into the block. It will then tell the extension which block was checked out by passing the block's index value via the AddHeader() method in the pre-proc header notification.

The extension will then check out the same block, quickly make a copy of it, and check the block back into the pool as being "available." In this sample, the filter writes a quick message into the block and the extension will simply send back to the browser this message.

The SMemBlock class contains one or more MemBlock objects. These MemBlock objects contain a header and body. The header will indicate the size of the data in the body (for speed reasons, the body size maximum is set to 4092 bytes--this is 4KB minus the entry for the 4-byte header).

The SMemLock class is a simple Mutex wrapper that is contained by the SMemBlock class. Its name is based on the name of the SMemBlock and will be used to synchronize access between threads to the shared memory pool.

REFERENCES

Windows NT Option Pack ISAPI Documentation

Visual C++ Online Documentation

Modification Type:MinorLast Reviewed:8/5/2004
Keywords:kbdownload kbfile kbinfo kbSample KB194706