Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to migrate an old CGI application from an existing Windows 2003 server (IIS 6.0) where it works just fine to a new Windows 2008 server with IIS 7.0 where we're getting the following problem:

After setting up the module handler and everything, I find that I can only access the CGI application (rdbweb.exe) file if I'm calling it via POST request (form submit from another page).

If I just try to type in the URL of the file (issuing a GET request) I get the following error:

HTTP Error 502.2 - Bad Gateway

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "Exception EInOutError in module rdbweb.exe at 00039B44. I/O error 6. ".

This is a very old application for one of our clients. When we tried to call the vendor they said we need to pay ~ $3000 annual support fee in order to start the talk about it. Of course I'm trying to avoid that!

Note that:

  • If we create a normal HTML form that submits to "rdbweb.exe", we get the CGI working normally. We can't use this as workaround though because some pages in the application link to "rdbweb.exe" with normal link not form submit.
  • If we run "rdbweb.exe". from a Console (Command Prompt) Window not IIS, we get the normal HTML we'd typically expect, no problem.

We have tried the following:

  • Ensuring the CGI module mapped to "rdbweb.exe".in IIS has all permissions (read, write, execute) enabled and also all verbs are allowed not just specific ones, also tried allowing GET, POST explicitely.
  • Ensuring the application bool has "enable 32 bit applications" set to true. Ensuring the website runs with an account that has full permissions on the "rdbweb.exe".file and whole website (although we know it "read", "execute" should be enough).
  • Ensuring the machine wide IIS setting for "ISAPI and CGI Restrictions" has the full path to "rdbweb.exe".allowed.
  • Changing the module from CGI to Fast CGI, not working also
  • Making sure we have the latest Windows Updates (for IIS6 we found knowledge base articles stating bugs that require hot fixes for IIS6, but nothing similar was found for IIS7).

Now the only remaining possibility we have instigated is the following Microsoft Knowledge Base article: http://support.microsoft.com/kb/145661 - Which is about:

CGI Error: The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

the article suggests the following solution:

Modify the source code for the CGI application header output. The following is an example of a correct header:

 print "HTTP/1.0 200 OK\n";  
 print "Content-Type: text/html\n\n\n";

Unfortunately we do not have the source to try this out, and I'm not sure anyway whether this is the issue we're having.

Can you help me with this problem? Is there a way to make the application work without requiring POST request? Note that on the old IIS6 server the application is working just fine, and I could not find any special IIS configuration that I may want to try its equivalent on IIS7.

share|improve this question

4 Answers 4

up vote 2 down vote accepted

Shortly: it might be a Delphi CGI application compiled with a Delphi version previous to D2007 last update (11.0.2902.10471). If it is the case you need the sources and a Delphi installation and recompile the application. Alternatively you should ask them just to recompile the app using a recent Delphi version.

(from http://forums.iis.net/t/1100323.aspx?PageIndex=2)

We found the problem which was causing our CGI to not respond on IIS 7. We actually narrowed the reason down to a line of code in the base class of all CGI applications written in Delphi (at least up to version 2005). This line of code is in the Run method of TCGIApplication and simply resets the standard input. On IIS 6 and prior, this line executes with no problem but on IIS 7 is raises an exception which causes the CGI application to crash and therefore not respond to requests. We are still investigating the side-effects of commenting this line out but that is our current solution. By removing this line, our CGI applications are now executing correctly on IIS 7.

Original author: Steven

share|improve this answer

We have a Delphi 5 CGI application that experienced the same issue on IIS 7. Our solution was similar to the one Steven posted above, however, we don't completely comment out the line marius mentions above. When I did, I saw that any Request.ContentString statement would bring back an empty string in the application. Our solution was to implement the code fix suggested at this article near the bottom. For your reference, here is a code snipped of our copy of CGIApp.pas with the change.

procedure TCGIApplication.Run;
var
  HTTPRequest: TCGIRequest;
  HTTPResponse: TCGIResponse;
begin
  inherited Run;
  if IsConsole then
  begin
    Rewrite(Output);
    //Win 7/2008 IIS7
    //Reset(Input);
    {$i-} {!!IIS7}
    Reset(Input);
    if IOResult <>0 then ;
    {$i+}
  end;
  try
    HTTPRequest := NewRequest;
    try
      HTTPResponse := NewResponse(HTTPRequest);
      try
        HandleRequest(HTTPRequest, HTTPResponse);
      finally
        HTTPResponse.Free;
      end;
    finally
      HTTPRequest.Free;
    end;
  except
    HandleServerException(Exception(ExceptObject), FOutputFileName);
  end;
end;
share|improve this answer

The CGI vendor confirmed that the application is not compatible with IIS 7.0 and they'll support it in future releases.

I think this suggests that the only fix is the code change mentioned in the Microsoft knowledge base article.

share|improve this answer

I had this problem (CGI GET not working with Delphi generated CGI) and I also wanted to keep a .cgi extension to my CGI's rather than .exe (which scares users!). IIS 7.5 doesn't seem to allow CGI's to have an extension other than .exe or .dll.

Here is a super neat work around involving PHP(!):

Basically you are going to get PHP to call your CGI and echo back the results.

On your IIS config, map *.cgi to php just as you would *.php. Instead of calling your CGI directly call a .cgi file with the following PHP code:

<?php

putenv('QUERY_STRING=' . $_SERVER['QUERY_STRING']);
echo system('C:... path your cgi...//...delphicgi.exe');

?>

Replace 'C:... path your cgi...//...delphicgi.exe' with your original Delphi CGI.

There you have it! Your users shouldn't notice any difference. Obviously, there is the performance hit of going via PHP. But at least you didn't need to rebuild your CGI's and you can have a .cgi extension!

share|improve this answer
    
Heck this site removed my PHP code! It was: <?php putenv('QUERY_STRING=' . $_SERVER['QUERY_STRING']); echo system('C:... path your cgi...//...delphicgi.exe'); ?> –  Mark Mather Feb 8 '13 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.