Schlagwort-Archive: ISAPI

Different error output between localhost and a remote host

In one of my ISAPI projects I set the HTTP status code to 400 or 500 in case of an error. I also add some more data (in the body) to give the user a better error message. On my development PC everything works fine. If I deploy the ISAPI I don’t get the additional body text. After a search on the web I found the solution:

https://stackoverflow.com/questions/3993941/in-iis7-5-what-module-removes-the-body-of-a-400-bad-request
https://gist.github.com/remi/929007

Thank you guys.

After setting the httpError „existingResponse“ to „PassThrough“ in web.config it works.

<?xml version="1.0"?>
<configuration>
  <system.webServer>
    <httpErrors existingResponse="PassThrough"></httpErrors>
  </system.webServer>
</configuration>

How to properly cleanup/shutdown a Delphi ISAPI (which uses Threads)

If You use Threads or global Objects (which are created in the initialization section for example) You have to cleanup/shutdown them in the OnTerminate event of the ISAPI Application. If You destroy/shutdown them in the finalization section in a unit it could end up in a hanging application pool in IIS on shutdown/reuse and some windows event log entries.
Weiterlesen

Long start/request times in Internet Explorer and bad code in ISAPIThreadPool.pas

I have created a web site which serves a lot of jpeg images (via <img /> – tags) from one of my web services. The web browser download most of this images simultaneously. In Internet Explorer I had the problem of long waiting times on start/request. See Screenshot. Weiterlesen

Problems with stack size/recursion in ISAPI DLL

In my actual ISAPI project I have a recursive function which in some cases is called about 300 times. In a normal EXE project it works. But in an ISAPI DLL it doesn’t. It raises an AV like this: „stack overflow at 0x77c3805a“

After some searching I found the explanation: „the maximum stack size of a thread that is created in a native IIS process is 256 KB“ The stack size of a normal EXE program is 1 MB. There is also no difference between 32bit and 64bit.

Here are some more information which helped me:
http://stackoverflow.com/questions/15883656/is-it-possible-to-change-the-default-thread-stacksize-for-a-dll-not-under-your-c
http://joel.inpointform.net/software-development/explanation-of-stack-heap-and-recursion-causing-stack-overflow/

Here is some example code:

procedure DoIt;

  procedure Recursion(const Step: Double);
  var
    aFormatSettings: TFormatSettings;
    aString: string;
    aNewStep: Double;
  begin
    //In my real project I got the AV during TFormatSettings.Create so I have made a demo with TFormatSettings.Create
    aFormatSettings := TFormatSettings.Create;
    aFormatSettings.DecimalSeparator := '.';
    aString := FloatToStr(Step, aFormatSettings);
    aNewStep := StrToFloat(aString, aFormatSettings);
    aNewStep := aNewStep + 1;
    //in an ISAPI the AV raises by < 2000 steps
    //in an EXE the AV raises by < 200000 steps
    if Step < 2000 then
      Recursion(aNewStep);
  end;

begin
  Recursion(1);
end;

DMVCFramework, statische Dateien (Bilder/jpeg) und HTML Header „Content-Length“

Während der Arbeit an der Webanwendung auf Basis des DMVCFrameworks gab es die Anforderung statische Dateien (Bilder) auszugeben. Innerhalb einer „normalen“ Anfrage welche Artikeldaten im JSON Format zurückgibt wurden die entsprechenden Links zu den Bildern mit übertragen. Beim Aufruf dieser URL’s wird die Anfrage vom DMVCFramework intern an TMVCStaticContents.SendFile weitergeleitet. Diese Methode gibt als ResponseStream das jpeg zurück. Dabei werden unter anderem der „Content-Type“ oder der „Last-Modified“ Header gesetzt. Außerdem das Feld „Content-Length“. Siehe
class procedure TMVCStaticContents.SendFile(AFileName, AMimeType: string; Context: TWebContext); Weiterlesen

Delphi XE3, WebBroker, ISAPI, DelphiMVCFramework, UTF-8, 64 Bit

Nachdem ich mich in den letzten Tagen mit den oben genannten Themen beschäftigt (und geärgert) habe möchte ich versuchen ein paar Erkenntnisse aufzuschreiben. Vorab die Info das es um die Erstellung einer Serveranwendung (ISAPI, 64 Bit, REST/Json Schnittstelle) geht. Weiterlesen