ISAPI Filter 可能拿来做些什么?1.改变客户Duan发送的请求数据(URL和头)。
2.控制URL映射到那个具体的物理文件。
3.控制匿名和基础认证时使用的用户名和密码。
4.认证完成后修改或分析一个请求。
5.修改一个返回到客户Duan的相应。
6.当出现“访问拒绝”应答时执行相应处理。
7.当一个请求完成后,执行一些处理。
8.当客户Duan连接被关闭后,执行一些处理。
9.记录特别日志或交互分析。
10.执行普通认证。
11.处理加密和压缩。
ISAPI Filter 开发要点
ISAPI过滤器必须以DLL形式实现
ISAPI过滤器必须提供GetFileVersion和HttpFilterProc函数,TerminateFilter函数是可选实现。
GetFileterVersion函数中需要提供版本信息和注册感兴趣的时间,在IIS装载该DLL时被调用一次,过滤器的初始化代码可放在此函数中进行。或放在dll的初始化函数DllMain中进行。
HttpFilterProc是事件处理进入点函数,当有该过滤器感兴趣的事件时,IIS会调用该函数。
TerminateFilter该函数在IIS卸载该过滤器时被调用(如停止IIS时),是可选实现。过滤器的清理代码可以放在此处。
过滤器事件列表事件 出现时间
SF_NOTIFY_READ_RAW_DATA Occurs when data is being read from the client. May occur more than once per request.
SF_NOTIFY_PREPROC_HEADERS Occurs immediately after IIS has pre-processed headers, but before IIS has begun to process header content.
SF_NOTIFY_URL_MAP Occurs after IIS has translated a URL to a physical path on the server.
SF_NOTIFY_AUTHENTICATION Occurs just before IIS authenticates the client.
SF_NOTIFY_ACCESS_DENIED Occurs just after IIS has determined that access is denied for the requested resource, but before IIS has sent a response to the client.
SF_NOTIFY_SEND_RESPONSE Occurs after the request has been processed by IIS, but before any headers are sent back to the client.
SF_NOTIFY_SEND_RAW_DATA Occurs as IIS sends raw data back to the client. May occur more than once per request.
SF_NOTIFY_END_OF_REQUEST Occurs at the end of the request.
SF_NOTIFY_LOG Occurs at the end of a request, just before IIS writes the transaction to the IIS log.
SF_NOTIFY_END_OF_NET_SESSION Occurs when the network session with the client is ending.