Link to home
Start Free TrialLog in
Avatar of bustany
bustanyFlag for United States of America

asked on

ISAPI Filter not getting invoked (or loaded)

Platform:  Win NT Server 4.0 + SP6 with IIS4.0

I copied two sample ISAPI filter, one from the Visual C++ ISAPI programming book and the other from MSDN.  They are both created in VC++ projects.  They compiled successfully.

Based on the instructions, I am supposed to list the full path for each DLL in the registry at:
"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W3SVC\Parameters\FilterDLLs"

1. First, there was no such key, so I had to create FilterDLLs key.

2. I listed both DLLs as such:
D:\Books\Pro VC++ ISAPI\SimpleFilter\Debug\SimpleFilter.dll, D:\Program Files\Microsoft Visual Studio\MyProjects\Filter\Debug\Filter.dll
However, neither one gets invoked when I http to the server.  Both filters have OnUrlMap() and all the other methods so any http request should load and invoke the filter.  however, nothing is happening.

Here is SimpleFilter.dll

/////////////////////////////////////////////////
//  SimpleFilter.cpp


#include <windows.h>
#include <httpfilt.h>


//  DebugMsg() is used for debugging
#define DEST buff
#define DebugMsg(x)            \
   {                           \
      char buff[256];          \
      wsprintf x;              \
      OutputDebugString(buff); \
   }


BOOL WINAPI GetFilterVersion(HTTP_FILTER_VERSION* pVer)
{
   // The version of the web server this is running on
   DebugMsg(( DEST, "Web Server is version is %d.%d\n",
              HIWORD( pVer->dwServerFilterVersion ),
              LOWORD( pVer->dwServerFilterVersion ) ));

   // Our filter version nuumber.
   pVer->dwFilterVersion = MAKELONG( 1, 0 );   // Version 0.1

   // The description
   strcpy( pVer->lpszFilterDesc, "Simple Filter, 0.1" );

   // Requests Everything
   pVer->dwFlags = ( SF_NOTIFY_SECURE_PORT         |
                     SF_NOTIFY_NONSECURE_PORT      |
                     SF_NOTIFY_READ_RAW_DATA       |
                     SF_NOTIFY_PREPROC_HEADERS     |
                     SF_NOTIFY_URL_MAP             |
                     SF_NOTIFY_AUTHENTICATION      |
                     SF_NOTIFY_SEND_RAW_DATA       |
                     SF_NOTIFY_LOG                 |
                     SF_NOTIFY_END_OF_NET_SESSION  |
                     SF_NOTIFY_ORDER_DEFAULT );

   return TRUE;
}


DWORD OnReadRawData(HTTP_FILTER_CONTEXT *pfc,
                    HTTP_FILTER_RAW_DATA *pRawDataInfo)
{
   DebugMsg((DEST,"OnReadRawData\r\n"));
   return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


DWORD OnPreprocHeaders(HTTP_FILTER_CONTEXT* pFC,
                       HTTP_FILTER_PREPROC_HEADERS* pHeaderInfo)
{
   DebugMsg((DEST,"OnPreprocHeaders\r\n"));

   CHAR achUrl[512];
   DWORD cbURL=512;

   pHeaderInfo->GetHeader(pFC, "url",achUrl,&cbURL);

   DebugMsg((DEST,"Requested URL is:%s.\r\n",achUrl));
   return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


DWORD OnUrlMap(HTTP_FILTER_CONTEXT* pFC, HTTP_FILTER_URL_MAP* pUrlMapInfo)
{
   DebugMsg((DEST,"OnUrlMap\r\n"));
   DebugMsg((DEST,"PhysicalPath: %s\r\n",pUrlMapInfo->pszPhysicalPath));
   return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


DWORD  OnAuthentication(HTTP_FILTER_CONTEXT* pFC,
                        HTTP_FILTER_AUTHENT* pAuthInfo)
{
   DebugMsg((DEST,"OnAuthentication\r\n"));
   DebugMsg((DEST,"UserName: %s\r\n",pAuthInfo->pszUser));
   return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


DWORD OnSendRawData(HTTP_FILTER_CONTEXT* pFC,
                    HTTP_FILTER_RAW_DATA* pRawDataInfo)
{
   DebugMsg((DEST,"OnSendRawData\r\n"));
   return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


DWORD OnLog(HTTP_FILTER_CONTEXT* pFC, HTTP_FILTER_LOG* pLogInfo)
{
   DebugMsg((DEST,"OnLog\r\n"));
   DebugMsg((DEST,"Target:%s\r\n",pLogInfo->pszTarget));
   return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


DWORD OnEndOfNetSession(HTTP_FILTER_CONTEXT* pFC)
{
   DebugMsg((DEST,"OnEndOfNetSession\r\n"));
   return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


DWORD WINAPI HttpFilterProc(HTTP_FILTER_CONTEXT* pFC,
                            DWORD NotificationType, VOID* pvData)
{
   DWORD dwRet;

   // Send this notification to the right function
   switch ( NotificationType )
   {
   case SF_NOTIFY_READ_RAW_DATA:
      dwRet = OnReadRawData( pFC, (PHTTP_FILTER_RAW_DATA) pvData );
      break;
   case SF_NOTIFY_PREPROC_HEADERS:
      dwRet = OnPreprocHeaders( pFC,
                                (PHTTP_FILTER_PREPROC_HEADERS) pvData );
      break;
   case SF_NOTIFY_URL_MAP:
      dwRet = OnUrlMap( pFC, (PHTTP_FILTER_URL_MAP) pvData );
      break;
   case SF_NOTIFY_AUTHENTICATION:
      dwRet = OnAuthentication( pFC, (PHTTP_FILTER_AUTHENT) pvData );
      break;
   case SF_NOTIFY_SEND_RAW_DATA:
      dwRet = OnSendRawData( pFC, (PHTTP_FILTER_RAW_DATA) pvData );
      break;
   case SF_NOTIFY_LOG:
      dwRet = OnLog( pFC, (PHTTP_FILTER_LOG) pvData );
      break;
   case SF_NOTIFY_END_OF_NET_SESSION:
      dwRet = OnEndOfNetSession(pFC);
      break;
   default:
      DebugMsg(( DEST,
                 "[HttpFilterProc] Unknown notification type, %d\r\n",
                 NotificationType ));
      dwRet = SF_STATUS_REQ_NEXT_NOTIFICATION;
      break;
   }
   return dwRet;
}


Thank you





ASKER CERTIFIED SOLUTION
Avatar of ShaunWilde
ShaunWilde

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mikeblas
mikeblas

Are you sure that you have IIS installed?  If you don't have it installed, some of the W3SVC keys get created by NT, but aren't populated.

Can you get plain webpages from your machine?

Have you tried debuggging? Is your DllMain() being executed?

..B ekiM
Avatar of bustany

ASKER

thank you.  it worked