Run CGI program under IIS 7.0

Looking around I didn’t find a good documentation on how to get good old CGI’s running on IIS 7 or 7.5. Here is a quick walkthrough:

1. Let’s write a quick CGI:
Take the following code and save it as simplecgi.cs in the directory c:\inetpub\wwwroot\cgi

using System;
using System.Collections;

class SimpleCGI
{
    static void Main(string[] args)
    {
        Console.WriteLine("\r\n\r\n");
        Console.WriteLine("<h1>Environment Variables</h1>");
        foreach (DictionaryEntry var in Environment.GetEnvironmentVariables())
            Console.WriteLine("<hr><b>{0}</b>: {1}", var.Key, var.Value);
    }
}

2. Change into the C:\inetpub\wwwroot\cgi directory and compile the source by using the following command-line:

%windir%\Microsoft.NET\Framework\v2.0.50727\csc.exe SimpleCGI.cs

You will have simplecgi.exe in the cgi directory. You can execute it on the command-line to see its output.

3. For security reasons every CGI has to be registered in the ISAPI/CGI Restriction list. To do that you have to open INETMGR, click the machine node (name of your machine) and find the ISAPI/CGI Restriction List menu icon.

image

Select the item and add the following entries in the dialog box:

image

Alternatively you can use the command-line:

%windir%\system32\inetsrv\appcmd set config -section:isapiCgiRestriction 
/+[path='c:\inetpub\wwwroot\cgi\simplecgi.exe',allowed='true',description='SimpleCGI']

4. The next step is to create a virtual directory that allows CGIs to execute. Right click the “Default Web Site” in INETMGR and select “Add Virtual Directory”. Add the following entries:

image

Here is the command-line which does the same:

appcmd add vdir /app.name:"Default Web Site/" /path:/cgi 
/physicalPath:"c:\inetpub\wwwroot\cgi"

5. One last step: we still don’t allow “Execute” access in this directory. For this you have to go to the Handler Mappings menu of the CGI virtual directory (make sure you select the CGI virtual directory on the left hand side!).

image

Go to the “Edit Feature Permissions” link in the Actions Menu on the right hand side, open it and check “Execute” and click “OK”.

image

via command-line:

appcmd set config "Default Web Site/cgi" /section:handlers 
-accessPolicy:"Read,Script,Execute"

Now you are ready to go. Type “http://localhost/cgi/simplecgi.exe and you should see the following output:

image

source : http://blogs.iis.net/thomad/archive/2010/04/04/how-to-run-a-cgi-program-under-iis-7-0-or-iis-7-5.aspx

Advertisements

About alamzyah
Name : Alamsyah Nick Name : Alamzyah Place of Birth : Jakarta, 04 June 1983 sex : Male Religion : Moslem Region : Jakarta, Indonesia Specialist : IT, Computer mail : alamzyah@gmail.com

One Response to Run CGI program under IIS 7.0

  1. Wan Cuff says:

    I just want to say I’m very new to blogging and site-building and definitely savored your web-site. Probably I’m going to bookmark your site . You really come with terrific posts. Thanks a lot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: