Home arrow IIS arrow Page 2 - An Introduction To ISAPI

An Introduction To ISAPI

ISAPI extensions allow you to access the operating system on your web server (including API calls) while still communicating with your web site through the response object. In this article Raj gives us a nice introduction to ISAPI and also shows us two examples that he's made with Delphi and Paradox. The examples implement a simple login system and utilize a database. Even if you don't know Deplhi then you'll still be able to pick up the basics of ISAPI in a flash!

Author Info:
By: Raj Bakhru
Rating: 4 stars4 stars4 stars4 stars4 stars / 25
April 11, 2002
  1. · An Introduction To ISAPI
  2. · The Benefits of ISAPI
  3. · ISAPI Database Example
  4. · Conclusion

print this article

An Introduction To ISAPI - The Benefits of ISAPI
(Page 2 of 4 )

The most popular question an ISAPI developer receives is: "Why ISAPI?". As the title of this article suggests, ISAPI is generally a forgotten technology (although it is making a surge back to popularity with the new XML/SOAP technologies that rely on ISAPI- see "The Future of ISAPI" section). As many have realized, CGI isn't very efficient, nor is it very secure. ISAPI was developed to fulfill the deficiencies where CGI fails.

One of the main reasons that ISAPI is more efficient than CGI is because ISAPI remains memory resident. CGI, on the other hand, unloads after it's called. Each time the CGI executable is called, the server must load the CGI process back into memory, whereas ISAPI will already be in memory and can therefore serve the request in a much faster time. For large-scale sites like EBay, ISAPI has been a savior. If EBay were to run on CGI, the burden on their servers would be nearly doubled, resulting in crashing and poor performance, and thus resulting in less business.

Another great benefit of ISAPI is the flexibility of the process. Like CGI executables, the user can use the compiler's embedded functions and the Windows API to access the operating environment of the server. Some great applications of this are, for example, creating an ISAPI remote administration program. ISAPI will allow the application to access the Windows list of functions, kill processes being run by the server, view a screenshot of the hosting screen, and perform countless other administration options, all while providing a secure and robust platform to do so.

A Simple ISAPI Application

In this section we'll go through the steps to make a simple ISAPI application in Delphi. The reason I chose Delphi is because of the ease of use of the language - anyone who isn't familiar with Delphi should be able to follow along and pick it up very easily. The application we'll make in this article is a simple form submission handler. The data from the form will be output back to the user and stored in a text file.

Fire up Delphi and create a new form project called webmodulbegin. Go to File->New Project->Other..->WebServer Application->ISAPI/NSAPI Dynamic Link Library (NOTE: NSAPI is the Netscape Server Application Programming Interface. It is very similar to ISAPI but will only run on Netscape's Enterprise Servers). The default name is WebModule1, but for our example we need to rename the project to WebInterfaceForm. You'll also see a list on the left that contains a hierarchy consisting of WebInterfaceForm with "Actions" below it. The "Actions" menu defines the various functions that the program calls. For example to access our_ISAPI_app.dll/welcome, we create an Action item for "/welcome". If an action doesn't exist for welcome, then the application checks for a default action. If this doesn't exist, an exception is raised.

Let's go ahead and create an action item (you do this by right clicking on "Actions" and choosing "Add Item"). We'll call our new action "Welcome" and make it the default action. In the PathInfo field, enter: /welcome. In the events tab, double click "OnAction". This defines what is to happen if a request for this function is received. This is where we'll define the output we want. Below is the code entered for that procedure:

procedure TWebInterfaceForm.WebInterfaceFormWelcomeAction(Sender: TObject;

Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);


if Request.Method = 'GET' then


//This is where we define the output for the form- once the form is submitted,

//the POST method is called and our output is defined by the "else" clause.

response.content := '<html><head><title>Learning ISAPI</title></head><h3>Learning ISAPI!</h3>'

+ '<form name="isapiform" method="POST" action="' + request.URL + '">'

+ '<strong>Please enter the following information</strong><br>'

+ 'Name: <input type="text" name="name"><br>'

+ '<input type="checkbox" name="likes" value="true" checked> I like ISAPI!<p>'

+ '<input type="submit" value="View Output"></form></html>';

//The above defines the output. It outputs a form prompting for the user's name

//and asks whether they like ISAPI. Request.url is a method we can use to find the

//URL of the page. We use this as our "action" because the same function as this will

//handle the form. (see below)




//This is where we handle our form and output the submitted information

//First, we'll check to see if the "NAME" field isn't blank, if it is, we'll output

//a message stating that it was required.

if request.contentfields.values['name'] = '' then

response.content := '<html><head><title>Error!</title></head><h3>Error!</h3><p>The name field is required!<br>'

+ '<a href="javascript:history.go(-1);">Back</a>';

//If there was no error, response.content still equals '', so we proceed through the rest by

//checking if response.content equals ''

if response.content = '' then


response.content := '<html><head><title>Congratulations</title></head><h3>Congratulations</h3><hr>'

+ 'The form resulted in the following information:<br>'

+ 'Your name is ' + request.contentfields.values['name'] + '.<br>';

//If they stated they like ISAPI, output a "thank you", otherwise output an "I'm sorry!"

if request.contentfields.values['likes'] = 'true' then

response.content := response.content + 'Thank you! You like ISAPI!'


response.content := response.content + 'I''m very sorry that you don''t like ISAPI!';

response.content := response.content + '</html>';




Now that we have our simple ISAPI application all ready to go, we need to "Build" it. We do this by first saving the project in its destination directory, and then we go to Project->Build saved_app_name.dll. The DLL will be built into the saved directory. To run the ISAPI file on your server, you will need to create a virtual directory that has executable permissions. To see an example of this ISAPI extension running, visit this page

Here's what it looks like in my web browser:

Running the ISAPI in IE

NOTE: IIS 4.0 has been known to have problems running ISAPI Version 2 Extensions (version 2 extensions are the standard extensions). If you're having this problem, sometimes reinstalling the NT 4.0 Option Pack fixes the error. Otherwise, if you'd like to continue working with ISAPI then you'll either need to either contact Microsoft for support or upgrade to Windows 2000 or XP. IIS 5.0/5.1 can run these without any problems. Two other good servers that run ISAPIs are Deerfield Website (formerly O'Reilly Website Pro) and Falcon Webserver.
blog comments powered by Disqus

- Beefing Up IIS: 10 Tips From A Former Solari...
- An Introduction To ISAPI
- Secure Your Web Server With SSL

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials