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("<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.


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


Alternatively you can use the command-line:

%windir%\system32\inetsrv\appcmd set config -section:isapiCgiRestriction 

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:


Here is the command-line which does the same:

appcmd add vdir /"Default Web Site/" /path:/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!).


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


via command-line:

appcmd set config "Default Web Site/cgi" /section:handlers 

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


source :

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 :

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: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: