Microsoft ISAPI SDK Samples

08 June 1996

Sample ISAPI Apps

ISAPI Applications are similar to CGI Applications, but are "in-process" (for Win32 platforms, they are DLLs instead of EXEs). There is a one-to-one mapping of CGI functionality in the ISAPI App interface.

Name: FormDump
Dependencies: Windows NT, IIS, Win32, C
Description: FormDump is an ISAPI App which demonstrates how to to obtain form data from a web browser, and also how to build a reply to the form. FormDump organizes inbound data into a memory structure, and uses that that data to build a HTML page; it also shows the dump of the server variables as well as the security context (domain, user name, etc.) in which the ISAPI App thread is running in.

Name: IS2WCGI
Dependencies: Windows NT, IIS, Win32, C++, VB
Description: IS2WCGI is an ISAPI App which helps in the migration of Windows CGI applications to ISAPI-based servers which may not natively support Win-CGI, such as IIS. IS2WCGI translates the inbound data of an ISAPI environment, building the private profile that the Windows CGI app is expecting, and sends the data back after the Windows CGI process completes. IS2WCGI, which implements Windows CGI version 1.2 functionality, allows a Windows CGI extension (normally written in Visual Basic) to basically run as an ISAPI App.

Name: ISAPIEcho
Dependencies: Windows NT, IIS, Win32, C++
Description: ISAPIEcho is an ISAPI App which uses Windows Sockets to pass HTML FORM parameter requests to a remote server. The server process, EchoServer, is implemented as a Windows NT service that accepts incoming requests and echoes them back to the ISAPI app; EchoServer is a simple TCP/IP echo server implemented using using multiple threads and completion ports. ISAPIEcho can establish and maintain socket connections on behalf of multiple clients. This "gateway-like" functionality is implemented using simple connection context manager. The connection context manager generates an HTTP Cookie, which is used by the browser to uniquely "identify" itself to the ISAPI app. Using Cookies clients create "virtual" connections with a remote echo server via the server and the ISAPI app. The Cookie is created when a connection with a remote server is established for the first time and reused for all subsequent client requests. This technique allows a browser to go through a series of HTML Forms by maintaining single connection to a remote server. The Cookie is expired and session with a remote host is terminated if the browser explicitly submits disconnect request, or the connection has been inactive for a specified period of time. In addition, ISAPIEcho includes the sample code that shows how to preprocess FORM GET and POST parameters into a C structure with a name and value pairs.

Name: ISrvMon
Dependencies: Windows NT, IIS, Win32, C
Description: ISrvMon is a simple ISAPI App which returns server load information to client, via an HTML Form. Server system information is obtained via the Win32 APIs: GlobalMemoryStatus(), GetProcessTimes(), GetCurrentProcess(), and GetSystemTime().

Name: Lottery
Dependencies: Windows NT, IIS, Win32, C
Description: Lottery is an ISAPI App which demonstrates how to use a persistent worker thread, allowing it to run independent of client requests. The worker thread continuously increments a lottery number, and when a client request comes in, the current lottery number is sent as a reply. The Lottery sample also illustrates how to change security tokens and how to use HTTP_STATUS_PENDING. Lottery is a sample referenced in presentations from the Microsoft Professional Developers Conference (PDC) ISAPI presentation.

Name: OLEISAPI
Dependencies: Windows NT, IIS, Win32, MFC, C
Description: Sample to allow any OLE automation server (including VB apps) to extend IIS.

Name: Redir
Dependencies: Windows NT, IIS, Win32, MFC, C
Description: Simple sample that redirects clients to a new site (for example for an ad) and logs the transaction.

Name: WebRun
Dependencies: Windows NT, IIS, Win32, MFC, C
Description: ISAPI app (and control panel applet) that allows administrators to run Win32 console commands remotely via a web page.

Sample ISAPI Filters

ISAPI Filters are programs which filter HTTP objects between web clients and web servers.

Name: AuthFilt
Dependencies: Windows NT, IIS, Win32, C
Description: AuthFilt demonstrates how to write an authentication filter based on an external datasource. Authentication is the process of accepting or denying a request from a client, so AuthFilt will be notified each time an authentication request comes in. This sample uses a text file to keep track of authorized users, but you might modify this sample to access a database which holds user info. For each authentication request, AuthFilt first looks in a cache of recently authenticated users, and when that fails, AuthFilt looks in the userdb.txt file. This shows an efficient way to authorize connections: a cache allows the filter to quickly authenticate users, and because each request comes in through the filter, speed is critical.

Name: CvtDoc
Dependencies: Windows NT, IIS, Win32, C++
Description: CvtDoc is an ISAPI filter which automatically converts documents from their native formats to HTML. Web content creators and webmasters often want to "publish" a document or data file to the Web. However, it can be very inconvenient to constantly run a conversion program to generate new HTML each time the document or data file is updated. Relying on the webmaster to run the conversion program for data that is often updated is also prone to error. CVTDOC is an ISAPI filter that converts documents to HTML dynamically as needed when the HTML file is accessed. If the HTML document is out of date (older than the source document) or missing, it is generated automatically from the ISAPI filter, based on "conversion programs" registered for the source document type in the registry. We provide sample conversion programs for Word, but its important to remember that this can be used for any document type for which you can find an HTML conversion program. Read more about the CvtDoc sample at http://www.microsoft.com/intdev/server/isfilter.htm.

Name: NewLog
Dependencies: Windows NT, IIS, Win32, C
Description: NewLog is an ISAPI Filter which extends the Microsoft IIS log file format to also include HTTP_USER_AGENT and HTTP_REFERER header information about the HTTP client. Also included with the sample is a Perl script which reads this new log file, creating a version which is compatible with normal HTTP log file utilities. NewLog is a sample referenced in presentations from the Microsoft Professional Developers Conference (PDC) ISAPI presentation.

Name: HomeFilt
Dependencies: Windows NT, IIS, Win32, C
Description: HomeFilt demonstrates a way to detect a request for the virtual root of the server and redirect it to another URL. Once the filter is registered in the filter chain, it will be called for each request. This sample examines the URL requested by the client, and if it is just a slash (/), the URL is changed to /sdk/homefilt/home.htm. The concept behind redirection is quite powerful: you might redirect your entire site to a single HTML file, or you might dynamically redirect requests to other HTML files chosen at random. This sample shows that redirection is not complex.

Name: UpCase
Dependencies: Windows NT, IIS, Win32, C
Description: UpCase demonstrates simple ISAPI filter functionality. This filter converts HTML response data to upper case if requested by the client. The request is made by specifying an extra subdirectory in the URL, which doesnt actually exist on the server, but is used by the filter to indicate that upper case is desired. The extra subdirectory is removed from the request before the HTTP server sees the request. UpCase demonstrates a few basic features of ISAPI filters: 1) parsing/modifying HTTP headers (in the request), 2) modifying data following HTTP headers (in the response), 3) saving state to be used by the filter later, and 4) adding request/response level functionality to the server.

Sample ISAPI Tools

In addition to ISAPI Apps and ISAPI Filters, there are other useful tools for ISAPI developers, some standalone applications, some CGI applications, etc.

Name: CGIWrap
Dependencies: Windows NT, IIS, Win32, C
Description: CGIWrap is a sample CGI App which wraps ISAPI App DLLs into CGI App EXEs. CGIWrap shows how to wrap an ISAPI DLL in a CGI executable, on systems that cannot use the DLL for some reason. Running NMake with this sample will cgiwrap.exe which can be renamed to match the name of the DLL. For example, to call foo.dll from this wrapper, rename cgiwrap.exe to foo.exe. This sample can also be used to aid in debugging. If you have a text file that contains a full http query (for POSTed forms; GET forms are all on the command line) then you can run this program under a debugger to analyze your sample. Please keep in mind that this is not the same environment as running as a service under IIS. Also, this sample, unlike IIS, is single-threaded.

Name: ISmoke
Dependencies: Windows NT, IIS, Win32, MFC, C
Description: ISmoke is a standalne application with various dialogs to help track down ("smoke" out) simple and common problems in ISAPI Apps written using Microsoft Foundation Class (MFC) library.