ISAPI开发概述

ISAPI可以完成很多功能,asp.net的实现底层也是通过isapi来解析asp.net的代码的。
通过开发isapi,然后在iis中配置后可以解析不同的文件。
比如java,perl的代码也可以通过加载isapi的方式在iis中进行访问

ISAPI
两种开发方式:扩展(如:aspnet_isapi.dll)和过滤(如:aspnet_filter.dll)

 

过滤可以实现许多功能,比如将简体转成繁体,大小写转换等, 参见UpCase



引用: 

Microsoft Visual Studio 2005, 中创建新项目时在 新建项目 对话框中没有找到 VisualC++ MFC ISAPI Extension DLL 模板。

 

因为 Microsoft 已删除 MFC ISAPI Extension DLL 模板为 Visual Studio 2005 发生此行为。

 

用于新 ISAPI 筛选或扩展开发, 我们建议您使用 MicrosoftInternet 信息服务 (IIS) 软件开发工具包 (SDK) ISAPI 入口 - Point 函数代替 MFC ISAPI 类。 Microsoft Windows Server 2003 Service Pack 1 (SP 1) 平台 SDK 包括许多 ISAPI 示例。 请以获取 PlatformSDK, 访问以下 MicrosoftWeb 站点:

http://www.microsoft.com/downloads/details.aspx?FamilyID=eba0128f-a770-45f1-86f3-7ab010b398a3&DisplayLang=en (http://www.microsoft.com/downloads/details.aspx?FamilyID=eba0128f-a770-45f1-86f3-7ab010b398a3&DisplayLang=en)

注意 时间少, 必须安装 Microsoft Windows 核心 SDK IIS SDK

默认情况下, SDK ISAPI 示例位于以下文件夹:

程序 Files\Microsoft 平台 SDK\Samples\Web\iis

有关如何创建 ISAPI 筛选器和扩展, 请访问以下 Microsoft Developer Network (MSDN) 网站:


最主要的代码如下:

  1DWORD WINAPI __stdcall HttpFilterProc(HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType, VOID *pvData)
  2{
  3    CHAR *pchIn, *pPhysPath;
  4    DWORD    cbBuffer,    cbtemp;
  5    PHTTP_FILTER_URL_MAP pURLMap;
  6    PHTTP_FILTER_RAW_DATA    pRawData;
  7
  8    switch (NotificationType)    {
  9
 10        case SF_NOTIFY_URL_MAP :
 11
 12            /* Check the URL for a subdirectory in the form of /UC/ or /uc/ */
 13
 14            pURLMap    =    (PHTTP_FILTER_URL_MAP)pvData;
 15
 16            pPhysPath    =    pURLMap->pszPhysicalPath;
 17
 18            pfc->pFilterContext    =    0;
 19
 20            for ( ; *pPhysPath; pPhysPath++
 21            {
 22                /* Ensure that there are at least 4 characters (checking for "\UC\") left in the URL before checking */
 23
 24                if (strlen(pPhysPath) > 3
 25                {
 26                    if (*pPhysPath == '\\' && (*(pPhysPath + 1== 'u' || *(pPhysPath + 1== 'U'&& (*(pPhysPath + 2== 'c' || *(pPhysPath + 2== 'C'&& *(pPhysPath + 3==    '\\')
 27                    {
 28                        /* Now that we've found it, remove it by collapsing everything down */
 29
 30                        for ( ; *(pPhysPath + 3) ; pPhysPath++)
 31                            *pPhysPath = *(pPhysPath + 3);
 32
 33                        /* NULL terminate the string */
 34
 35                        *pPhysPath = '\0'
 36
 37                        /* And set the flag to let the SF_NOTIFY_SEND_RAW_DATA handler know to uppercase the content */
 38
 39                        pfc->pFilterContext    =    (VOID    *)1;
 40
 41                        /* Break us out of the loop - note that this will only find the first instance of /UC/ in the URL */
 42
 43                        break;
 44                    }

 45                }

 46            }

 47
 48            break;
 49
 50        case SF_NOTIFY_SEND_RAW_DATA :
 51
 52            if (pfc->pFilterContext)
 53            {
 54                pRawData = (PHTTP_FILTER_RAW_DATA)pvData;
 55
 56                pchIn    =    (BYTE    *)pRawData->pvInData;
 57
 58                cbBuffer = 0;
 59
 60                if (pfc->pFilterContext    == (VOID *)1)
 61                {
 62                    /* 
 63                    As this is the first block, scan through it until 2 CRLFs are seen, to pass
 64                    all of the headers.
 65                    */

 66
 67                    for ( ; cbBuffer < pRawData->cbInData - 2; cbBuffer++)
 68                    {
 69                        if (pchIn[cbBuffer]    == '\n' && pchIn[cbBuffer + 2]    == '\n')
 70                        {
 71                            cbBuffer += 3;
 72
 73                            break;
 74                        }

 75
 76                        cbBuffer++;
 77                    }

 78
 79                    for (cbtemp = 0; cbtemp < (cbBuffer - 3); cbtemp++
 80                    {
 81                        if (pchIn[cbtemp] == '/' && pchIn[cbtemp + 1== 'h' && pchIn[cbtemp + 2== 't' && pchIn[cbtemp + 3== 'm')
 82                        {
 83                            pfc->pFilterContext    =    (VOID    *)2;
 84
 85                            break;
 86                        }

 87                    }

 88
 89                    if (cbtemp ==    cbBuffer)
 90                        pfc->pFilterContext    =    0/* not an    html file */
 91                }

 92
 93                /* Now uppercase everything */
 94
 95                if (pfc->pFilterContext)
 96                    for ( ; cbBuffer < pRawData->cbInData; cbBuffer++)
 97                        pchIn[cbBuffer] = (pchIn[cbBuffer] >= 'a' && pchIn[cbBuffer] <= 'z'? (pchIn[cbBuffer] - 'a' + 'A') : pchIn[cbBuffer];
 98            }

 99
100            break;
101
102        default :
103
104            break;                
105    }

106    
107    return SF_STATUS_REQ_NEXT_NOTIFICATION;
108}


 

posted @ 2007-03-14 14:37  永春  阅读(4127)  评论(0编辑  收藏  举报