IIS
  Home arrow IIS arrow Page 2 - An Introduction To ISAPI
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
IIS

An Introduction To ISAPI
By: Raj Bakhru
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2002-04-11

    Table of Contents:
  • An Introduction To ISAPI
  • The Benefits of ISAPI
  • ISAPI Database Example
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    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);

    begin

    if Request.Method = 'GET' then

    begin

    //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)

    end

    else

    begin

    //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

    begin

    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!'

    else

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

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

    end;

    end;

    end;


    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.

    More IIS Articles
    More By Raj Bakhru


     

    IIS ARTICLES

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


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway