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!
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:
+ '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:
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.