Sharing Data Between ISAPI Filters & ISAPI Extensions

ID: Q194706


The information in this article applies to:
  • Microsoft Internet Server Application Programming Interface (API)


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. Click the file names below to download the files:

Smemext.exe
Smemfilt.exe
For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center. 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

Additional query words:

Keywords : kbfile kbnokeyword
Version : winnt:
Platform : winnt
Issue type : kbinfo


Last Reviewed: December 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.