views:

216

answers:

3

I have an application implemented as an ISAPI filter whose behavior needs to change depending on whether it is being loaded by ISA or IIS. During GetFilterVersion it needs to register for SF_NOTIFY_SEND_RAW_DATA if being loaded by ISA or SF_NOTIFY_SEND_RESPONSE if being loaded by IIS.

There doesn't seem to be any information about the server passed to GetFilterVersion. Are there some tricks that might identify and distinguish between IIS and ISA?

[edit]

The application needs to know what server is loading it at initialization time, during the GetFilterVersion call. There is no current request, so attempting to get SERVER_VARIABLE from header variables will not work; there are no header variables at this point.

To elaborate, my application sets response headers, such as cookies and cache control headers. When running in the context of an ISA server, it must use the SF_NOTIFY_SEND_RAW_DATA event to complete this operation, modifying the raw data being sent by the ISA proxy. In IIS, however, using this notification comes with a severe performance penalty, so the application should use SF_NOTIFY_SEND_RESPONSE. SF_NOTIFY_SEND_RESPONSE will not work with ISA because this event does not get fired for proxied responses, only for responses which originate from the ISA itself, such as error pages. Finally, registering for events happens once during GetFilterVersion() and cannot be modified once the filter is loaded.

So the app needs to know, during initialization, when it decides to register for SF_NOTIFY_SEND_RESPONSE or SF_NOTIFY_SEND_RAW_DATA, whether it is being loaded by IIS or ISA.

A: 

I have only written isapi applications, not filters. but from an isapi application, you can call GetServerVariable and request the value of 'SERVER_SOFTWARE'

see http://msdn.microsoft.com/en-us/library/ms525335.aspx

if you can't call "GetServerVariable" from a filter, then i don't know how to do it.

-don

Don Dickinson
Thanks for the reply. Unfortunately, GetServerVariable isn't callable at the point where the filter needs the information. GetFilterVersion is implemented by my ISAPI filter and gets called once when IIS/ISA loads the filter. This is the opportunity for the filter to tell IIS what event notifications it needs. An HCONN handle is not passed to this function because this happens before clients connect. By the time a client connection is established, and GetSErverVariable could be called, it's too late for the filter to change its event notifications.
veefu
A: 

you might be able to get SERVER_SOFTWARE (or another variable indicating ISA vs. IIS) from the environment via getenv().

ax
+2  A: 

Recent versions of IIS and ISA should both operate with worker processes. The name "w3proxy.exe" belongs to ISA and "w3wp.exe" belongs to IIS. Acquire the current process name and test it, voila.

HANDLE winapi GetCurrentProcess()

and this:

DWORD WINAPI GetModuleFileNameEx(
  __in      HANDLE hProcess,
  __in_opt  HMODULE hModule,
  __out     LPTSTR lpFilename,
  __in      DWORD nSize
);

Should do the trick

Hassan Syed
Thanks! That's the kind of thing I thought might exist, but didn't remember enough windows api or know enough about IIS/ISA to find.
veefu