Monday, October 31, 2005

ISAPI extension doesn't write to log in IIS 5 when status code is wrong

For a long time, we've experienced a problem in which we saw that no request to our ISAPI extension was written to the IIS log. This only happened in IIS 5 and not in IIS 6, so we thought this is an IIS 5 problem.
However, it always felt strange to me, since this is very strange bug, and I didn't see any reference to it on the web.
I tried tweaking our HttpExtensionProc function, but couldn't not find what the problem is, until yesterday, I tried calling the base class (CHttpServer) implementation, and there, I saw that the dwHttpStatusCode member of the EXTENSION_CONTROL_BLOCK structure is set to an error value, and this caused the request to our ISAPI extension to be written to the log.

A quick search showed me that in the beginning of our HttpExtensionProc function, we set the dwHttpStatusCode member to 0, and then, we never change it. This cause the request to work well, but IIS 5 doesn't write the request to the log. IIS 6 changed this behavior, and does write the request to the log.

I guess the problem started because someone copied a sample code from somewhere, and that code initialized the member t the function start, and set it properly at the end, but our coder only took the first part, and forgot to set it in the end, and since it worked, no one really noticed.
Only later, we saw that log is not written, but we couldn't find the reason.

Well, now we've finally found it.

0 Comments:

Post a Comment

<< Home