ISAPI and Forms

Overview

HTML forms are the backbone of many Web applications, so it is important to implement form processing correctly. If your Web site receives only a moderate number of requests at any given time, and your form processing requirements aren't substantial, then form processing using ASP scripts would probably be your best choice. See the User Form Input with GET and User Form Input with POST samples for a demonstration of how ASP form processing works.

However, if your Web site is very busy, or even more importantly, if your form processing tasks are time-consuming and involved, then you should investigate using ISAPI extensions to perform your form processing. This sample demonstrates how an ISAPI extension can be used in such a capacity.

Code Tour

The code for this sample has been subdivided into several different files. The main file, FORMDUMP.CPP, implements the DLL entry-point function DllMain, as well as the ISAPI extension entry-point functions GetExtensionVersion and TerminateExtension.

The entry-point function HttpExtensionProc is also provided in FORMDUMP.CPP, and the bulk of the flow-control for the extension is performed in this function. When HttpExtensionProc is invoked, the extension sends an HTTP response header to the client browser. The extension then parses the inbound form fields, and sends information about each of those form fields to the client, as well. The extension next calls the WhoAmI function, implemented using the Windows LookupAccountSid function, to determine the security context in which the client browser is running. Finally, SendVariables is used to send an HTML list of some of the more important server variables and values.

The other key file in this project, KEYS.CPP, provides an interface that you can use to access the form data that is passed to the extension with either the GET or POST method. The function GetKeyList is called first, to create a linked list of key-value pairs. GetKeyInfo is then used to walk through the linked list, and access information about each key in the list. A third project file, HTML.CPP, provides a series of reusable wrappers for the most common HTML tasks. For instance, the function HtmlCreatePage can be used to write the beginnings of an HTML page, including the <HTML>, <TITLE>, and <BODY> tags, to the client browser.

Location

This project is available in the ...\isapi\extensions\formdump subdirectory of the IIS samples directory.