Application and Script Problems

Testing CGI Scripts

You can use a Perl script to test for the proper installation and execution of Common Gateway Interface (CGI) scripts with Internet Information Server.

Use a text editor to create a file with the following lines of code. Save the file in the /Scripts directory as Hello.pl.


print "Content-Type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Hello World</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<H4>Hello World</H4>\n";
print "<P>\n";
print "Your IP Address is $ENV{REMOTE_ADDR}.\n";
print "<P>";
print "<H5>Have a nice day</H5>\n";
print "</BODY>\n";
print "</HTML>\n";

After you create the file, configure Perl to run securely with Internet Information Server. Do not locate Perl.exe in any directory accessible by a user. Create a script mapping in the Registry for Perl.exe to enable the script to run by using Perl.

To configure script mapping for Perl

1. Click the Start button, then point to Run. In the Open box, type regedt32.exe and then click OK.

2. Click the HKEY_LOCAL_MACHINE window and locate the following key:

\System
\CurrentControlSet
\Services
\W3SVC
\Parameters
\ScriptMap

3. From the Edit menu, click Add Value.

4. In the Add Value dialog box, enter the value name .pl with the data type REG_SZ.

5. In the String Editor dialog box type the string value

full path\perl.exe %s

and click OK.
This instructs Internet Information Server to interpret all files with the extension .pl by using Perl.exe.

6. To implement these changes, quit the Registry Editor, then stop and restart the WWW service.

7. Test the Perl script with your browser. For example, in Internet Explorer, type

http://Servername/scripts/helloworld.pl?

Programs Attempt to Download to Client Computers

When you attempt to run a script on a client Web browser, an Unhandled File Type dialog box might appear. It requests that you save the file as a different filename or in a different location (Save As).

The problem is that the /Scripts directory has both Read and Execute access permissions set in Internet Service Manager. To work around this problem, do one of the following:

http://myserver/scripts/test.exe?

Programs from 16-bit Compilers Fail to Run

A CGI script compiled with a 16-bit C compiler might fail to run on Internet Information Server.

For example, say you use a 16-bit compiler to compile and build an executable file out of this C language source code:


#include <stdio.h>
void main()|
{
printf( "Content-type: text/html\n\n" );
printf( "<BODY BGCOLOR=\"#FFFFF0\" TEXT=\"#0000FF\">" );
printf( "<TITLE>This is a Test page</TITLE>" );
printf( "<h2>Hello World.</h2><br>" );
printf( "<h1><center>End of the test page.</center></h1>" );
printf( "</BODY>\n" );
}

If you then run the .exe file from the command prompt of Windows NT, the correct HTML output is generated. However, the results will be different if you place the same executable file in the /Scripts directory of the computer running Internet Information Server. If you try to run it from a Web browser by using the syntax.

http://Server/Path/File.exe?

it fails to generate the correct page.

To correct this problem, use a 32-bit C compiler to compile and build the C language source code. Microsoft C/C++ 4.0 and C/C++ 2.0 are 32-bit C compilers.

REMOTE_USER Variable Is Blank

Microsoft Internet Information Server does not return a user name for the variable REMOTE_USER unless both of the following are true:

If you use anonymous authentication, all users are authenticated with the IUSR_computername account, and the variable is not assigned a value by default.

One method of obtaining the REMOTE_USER variable is to create a batch file with the following lines and save it in the /Scripts directory, or a directory enabled in Internet Information Server for execute permissions:


@echo off
echo Content-Type: text/plain
echo.
Set

This batch file lists the environment variables used by Internet Information Server, including the REMOTE_USER variable. The list is returned as an HTML page to the Web browser that started the batch file.

Make sure you have configured script mapping for .bat or .cmd files, as described in the Internet Information Server Installation and Administration Guide.

You run the script from a browser by typing a URL with the syntax

http://Server_Name /Script

For example, you might type

http://www.company.com/scripts/environment.cmd?

The question mark at the end of the URL is required. The question mark signals the server that this is a GET request, which makes the server return script results rather than downloading the file to the user.

CGI Scripts Return Error

When submitting an HTML form or clicking a link to a script from a Web browser, the following message might be returned:


CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers. The headers it did return are:
Can't open perl script "c:\inetsrv\wwwroot\scripts\test.pl":
No such file or directory

This error is caused by missing or incorrect CGI header information. In this case, the headers are missing because the script file cannot be run. Therefore, the message was displayed instead of the output from the script.

The CGI specification calls for the script file to return at least one header. This header indicates how to fill out the remainder of the HTTP headers as required by that protocol. HTTP also requires a blank line between the end of the headers and the start of the document. Some servers return an error if the blank line is not present. The only headers currently supported by the CGI specification are:

For more information about these headers, see the HTTP and CGI protocol draft specifications at http://www.w3.org.