Tuesday, August 21, 2007
ISAPI Extensions and Filters
What are they? Basically, they are ways to extending Internet Information Services (IIS). They take two different approaches.
An ISAPI extension is much like a cgi or .net aspx page, but implemented at a much more low level using something like c or c++. It basically requires that you implement a few methods. The extension is accessed only when a url explicitly requests it. (Actually, in IIS 6 or greater it can be accessed the same way as a filter also. by using HSE_REQ_EXEC_URL.) It would typically reside in the /scripts directory. So an example would be: http://myth/articles/scripts/validate.dll?123456789012543
An ISAPI filter is much like writing an HttpModule for .net, except that it is called for every hit to the web site / or server if configured as such. It basically hooks into all requests to the web site or server and is called prior to .net framework call.
Dev Tips:
Testing Changes The fastest way to test your changes is to configure the filter IIS to point to your Debug version of the DLL. The best way to build when configured this way seems to be to keep the Services (from Administive Tools on the Start menu) open. When you want to build and test change do the following:
1. Stop the World Wide Web Publishing service.
2. Build (in Visual Studio, etc).
3. Start the World Wide Web Publishing service.
4. Attach to inetinfo.exe if you want to debug
5. Set breakpoint where desired.
6. Hit Url in IE.
What methods can I implement?
If you look in CHttpFilter class, you will see:
virtual DWORD HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD dwNotificationType, LPVOID pvNotification);
virtual BOOL GetFilterVersion(PHTTP_FILTER_VERSION pVer); virtual DWORD OnReadRawData(CHttpFilterContext* pfc, PHTTP_FILTER_RAW_DATA pRawData);
virtual DWORD OnPreprocHeaders(CHttpFilterContext* pfc, PHTTP_FILTER_PREPROC_HEADERS pHeaders);
virtual DWORD OnAuthentication(CHttpFilterContext* pfc, PHTTP_FILTER_AUTHENT pAuthent);
virtual DWORD OnUrlMap(CHttpFilterContext* pfc, PHTTP_FILTER_URL_MAP pUrlMap);
virtual DWORD OnSendRawData(CHttpFilterContext* pfc, PHTTP_FILTER_RAW_DATA pRawData);
virtual DWORD OnLog(CHttpFilterContext* pfc, PHTTP_FILTER_LOG pLog); virtual DWORD OnEndOfNetSession(CHttpFilterContext* pfc);
virtual DWORD OnEndOfRequest(CHttpFilterContext* pfc);
virtual DWORD OnAuthComplete(CHttpFilterContext* pfc, PHTTP_FILTER_AUTH_COMPLETE_INFO pAuthComplInfo);
virtual DWORD OnSendResponse(CHttpFilterContext*, PHTTP_FILTER_SEND_RESPONSE);
virtual DWORD OnAccessDenied(CHttpFilterContext*, PHTTP_FILTER_ACCESS_DENIED);
Where do I find out what the events that I can use and what they do?
http://msdn2.microsoft.com/en-us/library/ms524855.aspx
Where do I find a list of the IIS Server variables that I can use and what they are?
http://msdn2.microsoft.com/en-us/library/ms524602.aspx
Where can I get a simple example? http://www.codeproject.com/isapi/isapiredirector.asp
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment