Enhance IIS using ISAPI Filters

xiaoxiao2021-03-05  26

As a WWW server software, Microsoft's Internet Infomation Server (IIS) is easy to learn, and it is convenient to manage, it has been widely used. You can also make your own customized processing through the ISAPI filter to enhance the functionality of IIS. The ISAPI filter can customize the following processing: receive HTTP protocol header pre-processing, send HTTP protocol head pretreatment, send birth data pretreatment, obtain a biopsy, HTTP session end information processing, custom secure authentication mechanism, URL mapping Information processing, logging processing, etc. Flexible uses these customization, you can complete many seemingly difficult features to get unexpected effects. But the use of improper use of the ISAPI filter will also affect the performance of the server.

The development of the ISAPI filter is very simple, just complete three interface DLL functions. They are getFilterversion (), httpfilterproc (), TERMINATEFILTER (), you can view MSDN for detailed usage. The ISAPI filter is a DLL file, which is generally developed in C / C . To enable the ISAPI filter, you need to create a string term under the HKEY_LOCAL_MACHINE / SYSTEM / CURRENTCAL_MACHINE / SYSTEM / CURRENTCONTROLSET / SERVICES / W3SVC / Parameters of the registry, the name "Filter DLLS", the full path name of the ISAPI filter file . If this string item already exists, simply add its full path name to ";" between the different ISAPI filter files, you can add appropriate position according to the priority order. After setting up, restart the IIS service, your ISAPI filter works.

The author will take a specific application example.

Statistical analysis of access content: Usually we put a counter in the page you need to count, or use the ASP file to implement the count function. This approach cannot be applied to files such as other non-HTML formats such as readme.txt. If the log function using IIS is too taking space, it is inconvenient. The authors track the count statistics of several files of interest by customizing the URL mapping information processing, and record the results in a file.

Here is its source program.

Fcount.def: library fcountexports getfilterversion httpfilterproc TerminateFilter

Fcount.c: #include #include #include #include

#define logfile "c: //inetpub//fcount.log" #define pages 5char * URLS [] = {"/Default.htm", "/banner.gif", "/product/readme.txt", "/ Product / Product1.htm "," /Product/Product2.htm "}; int counts [pages];

BOOL WINAPI GETFILTERVERSION (http_filter_version * pver) {INT I;

PVER-> dwfilterversion = http_filter_revision; strcpy (pver-> lpszfilterdesc, "fcount"); PVER-> dwflags = sf_notify_url_map; / * Filter content * /

For (i = 0; i

DWORD WINAPI HTTPFILTERPROC (HTTP_FILTER_CONTEXT * PFC, DWORD NOTETYPE, VOID * PVNOTE) {INT I; Char Lurl [512]; char buf [16];

STRCPY ((pHTTP_FILTER_URL_MAP) PVNOTE -> PSZURL); _Strlwr (LURL); for (i = 0; i

Bool WinApi TerminateFilter (DWORD DWFLAGS) {INT I; Char BUF [16];

FOR (i = 0; i

The above two examples are compiled using VC 6.0, debugging on WinNT2000 SP3 and IIS 5.0.

转载请注明原文地址:https://www.9cbs.com/read-37138.html

New Post(0)