The reason to use ISAPI DLL's is that they are much faster that CGI (*.exe) files. This is particularly true when accessing a database (which is the main reason for writing a web server in the first place).
There are also commands to shut down groups of dll's. (Apparently, this capability was added with IIS 4.)
IIS allows you to manage the server as a "group of applications". The server root is always an application. You can add as many as you like. In general, IIS runs as a process and all the applications run in the "pooled" process. For test purposes (as well as for other reasons), you can run an application in its own (isolated) process - for performance reasons, there should be a maximum of 10 isolated applications (processes).
From a test point of view, the main benefit of running your site in an isolated process is that you can shut it down without affecting the other sites running under IIS. This means that to replace an active dll, it is not necessary to restart IIS, instead you just restart the process.
Defining an Isolated Process
The icon will change to an open box.
(This can also be accomplished via the command line.)
Once any dll in this application is loaded, the Unload button will allow you to stop the execution of all the related dll's so that you can write new versions over the old. (To enable the Unload button, you must reopen the Properties dialog box.)
Reference: IIS 5.1 Documentation - About Applications
Stopping an Isolated Application
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs APPUNLOAD /w3svc/1/root/fullPath This works cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs APPUNLOAD /w3svc/1/root This works cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs APPUNLOAD /w3svc/1/root/rlc/nist These fail cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs APPUNLOAD /rlc/nist cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs APPUNLOAD /w3svc/1/rlc/nist with the following error Error trying to get the path of the application:The "/w3svc/1/root/" prefix is based on the examples (where that is all that is entered) - I saw nothing in the help files indicating that your application name needs this prefix.
If the path on the vbs file is omitted, then it defaults to
C:\Documents and Settings\userName
It appears that there are 2 VisualBasic Script interpreters
C:\WINDOWS\system32\cscript.exe
Kill (or taskkill or pskill) is much faster than iisreset, but there is the problem of knowing exactly what to kill. For instance killing dllhost.exe produces errors that require you to manually restart IIS after every 6 compiles.
C:\Inetpub\AdminScripts
In a nutshell, this unloads all dlls in a directory
IIsObject = GetObject("IIS://localhost/path") IIsObject.AppUnloadReference on ADSI - http:www.agnisoft.com/adsi/Conf2000/3132.htm provides Delphi examples
VAR ogj : IADs; hr := ADsGetObject('IIS://localhost/xyz', IID_IADsContainer, obj); obj.IIS Administration Script Utility (adsutil)
Remember, I started with PWS and older versions of IIS that do not support iisreset.
Testing
Basically, the web server (IIS in my case) opens the *.dll file and never closes it. Microsoft does not provide any mechanism for a dll to close itself - it must be closed by the program that opened it. Microsoft also does not provide a way for IIS to close individual *.dll's. As a result, you must shut down and restart IIS before your changes will take effect. (This is why I originally suggested developing your application as a CGI file and testing this first before you use it as a dll.)
The other problem is that the Delphi IDE debugger can not be used unless Delphi runs the code. Thus, when IIS runs your code, you will need to use other methods to debug it.
Dataweb provides Free ISAPI Tools that
IIS no-cache option
Additionally, the switch applies to the entire site, not just the selected directory.
In XP, the switch is available via,
Control Panel / Administrative Tools / Internet Information Services
Test Solution
How to Restart IIS
Via the Control Panel
Killling dllhost.exe via the Task Manager
The remote procedure call failed and did not execute.
Using an *.bat file
@echo off : Kill_ISAPI_dlls.bat : 10-13-03 by Robert Clemenzi : This program terminates all currently loaded ISAPI dll's : It is used for debug echo taskkill.exe /f /im dllhost.exe taskkill.exe /f /im dllhost.exeWhen executed from a command prompt, these are the expected results
C:\INETPUB\WWWROOT\RLC>Kill_ISAPI_dlls.bat taskkill.exe /f /im dllhost.exe SUCCESS: The process "dllhost.exe" with PID 2632 has been terminated. SUCCESS: The process "dllhost.exe" with PID 3552 has been terminated.
Note: | Each operating system uses a different command for this.
Windows XP uses taskkill.exe,
Windows NT uses kill.exe exeName,
I have not found a similar command for Windows 98.
kill.exe is part of the Windows NT Resource Kit. |
Using a CGI file
taskkill.exe /f /im dllhost.exevia a CGI (*.exe) file so that I could restart the dll remotely - I never got it to work via a browser. Of course, it works perfectly when you just double click the *.exe file.
How to automatically update dll's
How it works - This Delphi program checks a sub-directory every 5 seconds. When a file is found, it shuts down the server and moves the file(s) to the main directory.
With this program, dll's are just as easy to test as CGI files.
This program does not work with Windows 2000 because taskkill.exe is not available.
Update: This program crashes IIS after changing dll's 5 or 6 times - apparently, there is a limit to how many "errors" IIS will log before it just quits.
A new program using IISRestart.exe is under development.
Author: Robert Clemenzi - clemenzi@cpcug.org