Friday, October 02, 2009

Configure Windows 7 IIS7 for ISAPI DLL

Windows 7 IIS7 require some configurations to get ISAPI DLL works.  It is not that straight forward compare to IIS 5.

Install IIS 7

  1. Go to Control Panel | Programs and Features | Turn on Windows features on or off (require privilege mode).
  2. Check “Internet Information Services and make sure “ISAPI Extensions” and “ISAPI Filters” is checked as well.
  3. Click OK button to start installation.

1

After finish install IIS 7, open your favorite web browser and enter URL http://localhost/ to make sure the IIS is working and running.  You might need to check your firewall setting and add exception for port 80 TCP traffic if necessary.

Configure for ISAPI DLL

Add Virtual Directory

First, you may need to add a virtual directory to host your ISAPI DLL:

  1. Open Internet Information Service Manager (require privilege mode)
  2. Right click on “Default Web Site” node and click “Add Virtual Directory” of popup menu:

2

Enter “Alias” and “Physical Path” of the virtual directory:

3

Enable ISAPI for Virtual Directory

To enable ISAPI for the virtual directory:

  1. Select the virtual directory node (e.g.: “ISAPI” in this example). 
  2. Double click the “Handler Mappings” icon. 
  3. Click “Edit Feature Permissions…” in Actions panel
  4. A “Edit Feature Permission” dialog prompt out
  5. Check “Execute”.
  6. Click OK button to commit the changes.

4

Enable Directory Browsing for Virtual Directory

This is optional but is convenient.  To enable Directory Browsing for a virtual directory:

  1. Select the virtual directory node (e.g.: “ISAPI” in this example). 
  2. Double click the “Directory Browsing” icon.
  3. Click “Enable” in Actions panel.

5

Edit Anonymous Authentication Credentials

  1. Select the virtual directory node.
  2. Double click the “Authentication” icon.
  3. Click to select “Anonymous Authentication” item.
  4. Click “Edit…” in Actions panel.
  5. A dialog will prompt out.
  6. Checked “Application pool identity” and press OK button to commit changes.

1

Enable ISAPI modules

  1. Click on the root node.
  2. Double click the “ISAPI and CGI Restrictions” icon.
  3. Click ”Edit Feature Setting …” in Actions panel.
  4. Check “Allow unspecified ISAPI modules” option.  This option allow any ISAPI dll to be executed under IIS.  If you don’t use this option, you will need to specify a list of ISAPI DLLs explicitly.

6

Edit Permission for Virtual Directory

  1. Select the virtual directory node (e.g.: “ISAPI” in this example). 
  2. Right click on the node and click “Edit Permission” of popup menu.
  3. A Properties dialog prompt out.
  4. Switch to “Security” page
  5. Click Edit button to show Permission dialog.
  6. Add “IIS_IUSRS” into the permission list.

7

Enable 32 bits ISAPI DLL on IIS 7 x64

This is only require if you are using IIS7 x64 and would like to run 32 bits ISAPI DLL on the IIS.  If your ISAPI DLL and IIS7 is both x86 or both x64, you may skip this step.

  1. Click “Application Pools” node.
  2. Click “DefaultAppPool” item
  3. Click “Advanced Settings …” from Actions panel.
  4. A “Advanced Settings” dialog prompt out
  5. Set “Enable 32-bits Applications” to True
  6. Click OK button to commit changes

8

If you didn’t enable this options for 32 bits applications, you may encounter the following errors when execute the ISAPI from web browser:

HTTP Error 500.0 - Internal Server Error

The page cannot be displayed because an internal server error has occurred.

HTTP Error 500.0 - Internal Server Error
Module    IsapiModule
Notification    ExecuteRequestHandler
Handler    ISAPI-dll
Error Code    0x800700c1
Requested URL   
http://localhost:80/isapi/isapi.dll
Physical Path    C:\isapi\isapi.dll
Logon Method    Anonymous
Logon User    Anonymous
 

You may now deploy your ISAPI DLLs into the virtual directory and start execute the library from web browser.

DataSnap and ISAPI DLL

You may create Delphi DataSnap ISAPP DLL library and deploy on IIS.  From time to time, you may encounter compilation error during development or deployment time if you have consume the ISAPI DLL.  This is because the ISAPI DLL invoked will cache in the application pool.  You are not allow to overwrite the ISAPI DLL while it’s being cached.

To overcome this problem, you need to perform Recycle operation:

  1. Click “Application Pools” node.
  2. Right click on “DefaultAppPool” item and click “Recycle…” item.

Capture

Deploying as ISAPI DLL is encourage during deployment stage as IIS will cache the ISAPI DLL for performance consideration.

However, the caching might not feasible during development stage as recycling need to be performed while overwrite the ISAPI DLL either by frequent compiling or overwriting.  You may consider compile the server modules as CGI application in development time.  Each invocation of CGI is a separate OS process and won’t be cache by IIS application pool.

Install CGI on IIS

  1. Go to Control Panel | Programs and Features | Turn on Windows features on or off (require privilege mode).
  2. Check “Internet Information Services and make sure “CGI” is checked.
  3. Click OK button to start installation.

2

Enable CGI Module

  1. Click on the root node.
  2. Double click the “ISAPI and CGI Restrictions” icon.
  3. Click ”Edit Feature Setting …” in Actions panel.
  4. Check “Allow unspecified CGI modules” option.

3

Consume DataSnap Server Methods via URL

The DataSnap server methods are using JSON as data stream via REST protocol.  For example, a simple EchoString server method defined as:

type
  {$MethodInfo On}
  TMyServerMethod = class(TPersistent)
  public
    function EchoString(Value: string): string;
  end;
  {$MethodInfo Off}

implementation

function TMyServerMethod.EchoString(Value: string): string;
begin
  Result := Value;
end;

To access this method compiled in ISAPI DLL via URL, the URL is something like

http://localhost/datasnap/MyISAPI.DLL/datasnap/rest/TMyServerMethod/EchoString/Hello

and the response text will be:

{"result":["Hello"]}

Likewise, a CGI URL is

http://localhost/datasnap/MyCGI.exe/datasnap/rest/TMyServerMethod/EchoString/Hello

 

Reference:

  1. DataSnap 2010 HTTP support with an ISAPI dll; Author: Tierney, Jim

34 comments:

raghu said...

It was very helpful.Thanks.

Cestbienmoi said...

Changing the default app pool is not the best choice on x64 => conflict with other applications.

It is better to create a new App Pool (32 bit without .net framework). And assign the pool to the new virtual directory.

Be carefull on production server (iis7/7.5). You do not need to authorize unknown isapi on production server, in handler mappings, you can "add Module Mapping" and specify your DLL as parameter of the isapi module.

Anonymous said...

Hi
I'm just wondering if you know a shared web hosting company supporting Delphi ISAPI.DLL's?
Thanks
Sam

Anonymous said...

Thanks for your help. This was a very good blog post, especially the part about the 32-bit settings.
Cheers, Trutz

Alexandre Machado said...

Nice how-to, thanks! The only comment is that is really better to create a new application pool and use it with your ISAPI modules.
Best reagards

Anonymous said...

Great Article!. It works for me 100%

grumfe said...

Thank you! It's like a miracle to find info about how to make this work. Thanks for posting this!

Anonymous said...

Thanks it was a great help and a step in the right direction but I'm still having problems connecting to a database. The Isapi dll doesn't seem to read the config file where the connection string is.

Chau Chee Yang said...

Perhaps you need to check the log and figure out why it doesn't work.

Harmen Schaap said...

You saved my day !!!
After searching for a day I finally found this great article. This worked 100% for me.

Anonymous said...

Very Nice!!!

I wasted a good time trying this alone. My experience with configuration of II6 was not enough.

Thanks

Aceto

Anonymous said...

Thanks,

This post save a lot of working time.

Aceto

Paul said...

Hi,
Thank you very much for this post. If helped me configure ISS 7 to use some Delphi Isapi dlls in few minutes. Thank you again.

Nase said...

Hi. I have IIS on Win7 OS and wanted to run ASP.Net 4.0 and PHP5.3. ASP.Net makes no problems and works without any problem and without configuration. PHP5.3 always throws the error: HTTP-Fehler 500.0 - Internal Server Error
C:\php5\php.exe - Der FastCGI-Prozess wurde unerwartet abgebrochen. Perhaps anyone has an idea?

Antoniazzi said...

Perfect for Win7 64bits and ISAPI dlls.

Tks

Antoniazzi said...

Perfect for Win7 64bits and Delphi Dlls.

mrozlog said...

Awesome Job!

Mike Rozlog

Anonymous said...

After scratching my head for 4 hours I came across this article and get the issue fixed.

Many thanks and keep on the nice work.

Anonymous said...

THANK YOU! THANK YOU! THANK YOU! Why can't Microsoft's own documentation be this good?

You have saved me after I wasted A LOT of time following other sources. The 32-bit step was particularly important for me.

Finally, I have my old C++ ISAPI .dll working in IIS.

Marcelo said...

Thank you. This was very helpful.

Anonymous said...

Thank you very much!!!

Excellent work.

Do you also know how to run IIS as a proccess and not as Service?

[ ]s
Duran

Chau Chee Yang said...

I have no idea how to configure IIS7 to run as application. You may try ask in http://serverfault.com/

Siva said...

Thanks for your tutorial.I developed ISAPI web application in dephi 7.Its working fine in windows xp but its not working on windows 7 32 bit.I did the same settings in IIS7 what mention in this article.For windows xp i did the component service for particular virtual directory identity account is system account is selected.I couldn't found this settings in windows.Please help to solve this problem.I am waiting for reply.Advance thanks to you

Chau Chee Yang said...

Siva, which windows settings you refer to? Perhaps you need to read carefully and try redo everything from scratch again.

Siva said...

Thanks for your quick reply.I tried so many times.My Delphi XE ISAPI dll working fine in Windows XP.The same application is not running in Windows 7 32 bit.I did the same settings what u mention the steps.In windows XP InetMgr Virtual Directory Tab Application Protection is High(Isolated) settings.I couldn't found the settings in Windows 7.How i can set this settings in Windows.Please help to solve this problem.Advance thanks to you.
Thanks & Regards
Siva

Andy said...

With your help I finally got my ISAPI up and running. Thank you very much!

Anonymous said...

This is not pure Windows 7 specific: on Windows server 2008 you can follow the same things (OK, it's IIS7/7.5 to on that platform ;)

To bad I already figured this out myself a few days ago (this would have made my task a lot easier).

Luis Ortega said...

Works perfect, however for some strange reason it does not work under secure site (https/SSL). Same DLL!

SathishKumar Sandupatla said...

really superb... it helps me to place ISAPI dlls in Windows IIS7.

Anonymous said...

Thanks, you saved me hours of headscratching

Anonymous said...

Thanks for your help.
This was a great blog post, especially the part about the 32-bit settings.
Cheers
Ernesto.

Anonymous said...

Thanks for your help.

Cosmin said...

Have a long and prosperous life :)

Anonymous said...

After configure this while i am trying to execute asp.net code which is save in c:\inetpub\webapplication1\webapplication1\default.aspx error occuted like this... what to do?? any suggestion.. i am using windows 7 ultimate 32 bit os.

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.