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) 网站:


最主要的代码如下:

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

 45ExpandedSubBlockEnd.gif                }

 46ExpandedSubBlockEnd.gif            }

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

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

 75InBlock.gif
 76InBlock.gif                        cbBuffer++;
 77ExpandedSubBlockEnd.gif                    }

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

 87ExpandedSubBlockEnd.gif                    }

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

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

 99InBlock.gif
100InBlock.gif            break;
101InBlock.gif
102InBlock.gif        default :
103InBlock.gif
104InBlock.gif            break;                
105ExpandedSubBlockEnd.gif    }

106InBlock.gif    
107InBlock.gif    return SF_STATUS_REQ_NEXT_NOTIFICATION;
108ExpandedBlockEnd.gif}


    本文转自永春博客园博客,原文链接: http://www.cnblogs.com/firstyi/archive/2007/03/14/674578.html ,如需转载请自行联系原作者

相关文章
|
安全 开发者 CDN
SharePoint Framework解决方案管理参考(二)
博客地址:http://blog.csdn.net/FoxDave 使用外部脚本 在使用现有的JavaScript脚本库时,开发者可以选择将它们包含在web部件代码包中,或者从外部的URL加载。
1327 0
|
UED 开发者 前端开发
SharePoint Framework解决方案管理参考(一)
博客地址:http://blog.csdn.net/FoxDave 使用SPFx,你的企业可以轻松构建解决方案跟Office 365和SharePoint Online集成。
1479 0