 |
Writing Form Processing ISAPI Extension DLLs
| Nik Okuntseff |
MS Exchange Server Programming |
Writing Form Processing ISAPI Extension DLLs
The real power of HTML forms is that they allow for client-server processing
over the Internet. For example, a survey form may be filled in by clients,
and results can be put into an SQL database. I have described HTML tags
used in HTML form design in previous topic. As you can see, the process
is simple and straightforward. However, to process the results of the form
submit operation, we need to write something for the server side.
As it turns out, with Microsoft Internet Information Server (IIS) this
is possible and relatively easy to do. In this section I will demonstrate
how this can be accomplished. I will describe steps that you need to do,
present a trivial working sample, and give a few hints that will perhaps
help you to avoid some problems.
Before You Start
-
Install IIS on a Windows NT server. IIS comes as part of Back Office. To
install: start with disk 1 of Microsoft Back Office, select IIS and follow
instructions on the screen. It would be a good idea to install IIS on a
"quiet" server. It is likely that during development you will need to reboot
your server a few times. You also have an option to install IIS on a Windows
NT workstation. This setup is known as Microsoft Peer Web Services. To
do it you need to run Inetstp.exe in I386\Inetsrv subdirectory on the Windows
NT Workstation 4.0 disk.
-
Your network should have TCP/IP protocol correctly configured. For example,
you need to be able to ping the server by name from other workstations.
-
IIS comes with some documentation on-line. It would be beneficial if you
browse through it to get the idea how everything works.
ISAPI versus CGI
It is possible to do Internet server programming with different means.
For example, you can write Common Gateway Interface (CGI) programs, execute
batch files in response to requests via the Internet, or write ISAPI (Internet
Server API) extension DLLs. Each of this methods has its own pros and contras.
The benefit of using ISAPI extension DLLs is that they are DLLs. They are
loaded in IIS process space and stay there. This is good for performance,
because there is no extra overhead associated with launching a new process
(as with CGI programs). In order to write ISAPI code you need to learn
a few things and follow some rules. This is realistic. You can set yourself
up and running in a matter of a day or so. For your reference Microsoft
has provided a nice collection of documentation about ISAPI in MSDN Library.
Writing ISAPI Extension DLL to Process Logon Requests
Let us write a trivial ISAPI extension DLL that processes logon requests
in response to the following HTML form:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=iso-8859-1">
<META NAME="Author" CONTENT="Nik Okuntseff">
<META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (WinNT;
I) [Netscape]">
<TITLE>LogonForm</TITLE>
</HEAD>
<BODY>
<FORM ACTION="http://mig/scripts/logon.dll" METHOD=POST>
<INPUT TYPE=HIDDEN NAME=MfcISAPICommand VALUE=LogonProc>
<P>Name<BR>
<INPUT TYPE=TEXT NAME=id VALUE="Your Name">
<P>Password<BR>
<INPUT TYPE=PASSWORD NAME=pw>
<P><INPUT TYPE=SUBMIT VALUE=OK><INPUT TYPE=RESET VALUE=Reset>
</FORM>
</BODY>
</HTML>
The MfcISAPICommand is a hidden control on the form to define a handler
function to be used to process the form on the server. You can read more
about it in Microsoft Technical Note 69: "TN069: Processing HTML Forms
Using Internet Server Extension DLLs and Command Handlers".
The DLL should generate different outputs depending on password supplied.
Thus, a browser user will see whether he or she supplied correct password.
This is how you can accomplish this:
-
Use you Visual C++ Development Studio to create a new project. Use ISAPI
Extension Wizard option when selecting the type for your project. Give
your project a name: Logon. Use default options. The Wizard will create
a skeleton DLL for you. Build it. Examine source files. They are very simple.
-
Put you DLL in the "scripts" subdirectory of your IIS installation.
-
Now verify whether this DLL actually works by using a browser on other
computer pointing to http://computer_name/sScripts/logon.dll (for example,
in my case the URL is: http://mig/scripts/logon.dll. In case of problems
verify whether you can ping the server, and whether World Wide Web Publishing
Service is running there. The DLL generates this default HTML text in response:
"This default message was produced by the Internet Server DLL Wizard. Edit
your CLogonExtension::Default() implementation to change it."
-
Edit default implementation by putting your own message string. For example,
make it look like the code below and verify whether it actually produces
the required output. You will need to stop World Wide Web Publishing Service
to replace the DLL, because it keeps the DLL loaded.
void CLogonExtension::Default(CHttpServerContext* pCtxt)
{
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("Response from my DLL...");
EndContent(pCtxt);
}
[ Contents |
Home
]
Send comments and suggestions to niko@wrconsulting.com
Copyright © 1997-1998 by Nik Okuntseff
|
 |