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
DWORD 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![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
switch (NotificationType) {
9![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
case SF_NOTIFY_URL_MAP :
11![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
/* Check the URL for a subdirectory in the form of /UC/ or /uc/ */
13![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
pURLMap = (PHTTP_FILTER_URL_MAP)pvData;
15![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
pPhysPath = pURLMap->pszPhysicalPath;
17![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
pfc->pFilterContext = 0;
19![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
for ( ; *pPhysPath; pPhysPath++)
21
{
22
/* Ensure that there are at least 4 characters (checking for "\UC\") left in the URL before checking */
23![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
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![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
for ( ; *(pPhysPath + 3) ; pPhysPath++)
31
*pPhysPath = *(pPhysPath + 3);
32![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
/* NULL terminate the string */
34![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
*pPhysPath = '\0';
36![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
/* And set the flag to let the SF_NOTIFY_SEND_RAW_DATA handler know to uppercase the content */
38![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
pfc->pFilterContext = (VOID *)1;
40![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
/* Break us out of the loop - note that this will only find the first instance of /UC/ in the URL */
42![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
break;
44
}
45
}
46
}
47![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
break;
49![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
case SF_NOTIFY_SEND_RAW_DATA :
51![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
if (pfc->pFilterContext)
53
{
54
pRawData = (PHTTP_FILTER_RAW_DATA)pvData;
55![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
pchIn = (BYTE *)pRawData->pvInData;
57![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
58
cbBuffer = 0;
59![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
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![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
for ( ; cbBuffer < pRawData->cbInData - 2; cbBuffer++)
68
{
69
if (pchIn[cbBuffer] == '\n' && pchIn[cbBuffer + 2] == '\n')
70
{
71
cbBuffer += 3;
72![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
break;
74
}
75![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
76
cbBuffer++;
77
}
78![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
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![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
break;
86
}
87
}
88![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
89
if (cbtemp == cbBuffer)
90
pfc->pFilterContext = 0; /* not an html file */
91
}
92![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
93
/* Now uppercase everything */
94![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
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![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
100
break;
101![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
102
default :
103![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
104
break;
105
}
106
107
return SF_STATUS_REQ_NEXT_NOTIFICATION;
108
}
本文转自永春博客园博客,原文链接:
http://www.cnblogs.com/firstyi/archive/2007/03/14/674578.html
,如需转载请自行联系原作者