日期:2014-05-16  浏览次数:21526 次

ISAPI Filter 输出自定义 HTML 代码的问题
正在学习编写 ISAPI Filter,请问如何输出自定义 HTML 代码? 这个代码加在哪里?我对C++不太熟悉,麻烦高手最好给出代码。
下面是我现在的代码。

C/C++ code

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <httpfilt.h>
#include <iostream>
#include <fstream>

using namespace std; 

using namespace System;

DWORD DoSendResponse(HTTP_FILTER_CONTEXT * pfc, HTTP_FILTER_SEND_RESPONSE * pResponse);

BOOL WINAPI __stdcall GetFilterVersion(HTTP_FILTER_VERSION *pVer)
{
    pVer->dwFlags = ( SF_NOTIFY_ORDER_DEFAULT | SF_NOTIFY_SEND_RESPONSE );
    pVer->dwFilterVersion = HTTP_FILTER_REVISION;
    strcpy(pVer->lpszFilterDesc, "Replace Server Header ISAPI filter, Version 1.0");
    return TRUE;
}

DWORD WINAPI __stdcall HttpFilterProc(HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType, VOID *pvData)
{
    switch (NotificationType)
    {
    case SF_NOTIFY_SEND_RESPONSE :
        return DoSendResponse(pfc, (HTTP_FILTER_SEND_RESPONSE *) pvData);
    default :
        break;
    }
    return SF_STATUS_REQ_NEXT_NOTIFICATION;
}

DWORD DoSendResponse(HTTP_FILTER_CONTEXT * pfc,HTTP_FILTER_SEND_RESPONSE * pResponse)
{
    System::IO::File::AppendAllText("c:\\abc.txt", "\r\n");

    char PATH_TRANSLATED[1024];
    DWORD cb;
    cb=sizeof(PATH_TRANSLATED);
    int len = 0;
    len = pfc->GetServerVariable(pfc, "PATH_TRANSLATED", PATH_TRANSLATED, &cb);
    String ^sPATH_TRANSLATED = gcnew String(PATH_TRANSLATED);

    System::IO::File::AppendAllText("c:\\abc.txt", sPATH_TRANSLATED);


    BOOL fServer = TRUE;
    DWORD dwServerError;
    fServer = pResponse->SetHeader(pfc, "Server:", "MyWebServer");
    if ( !fServer )
    {
        dwServerError = GetLastError();
        pfc->pFilterContext = (LPVOID)(DWORD64)pResponse->HttpStatus;
    }

    return SF_STATUS_REQ_NEXT_NOTIFICATION;
}





------解决方案--------------------
ISAPI filter不负责写出HTML内容,它只是监听以下事件而以。
SF_NOTIFY_READ_RAW_DATA when the web server has read data from the client 
SF_NOTIFY_PREPROC_HEADERS when data has been read and headers have been parsed 
SF_NOTIFY_URL_MAP when the web server is mapping a URL to a file 
SF_NOTIFY_AUTHENTICATION when the web server is authenticating a user 
SF_NOTIFY_ACCESS_DENIED if the user is denied access 
SF_NOTIFY_SEND_RAW_DATA when data is sent to the client 
SF_NOTIFY_END_OF_REQUEST when the request has ended 
SF_NOTIFY_LOG when a log entry is made 
SF_NOTIFY_END_OF_NET_SESSION when a connection has closed 
这里有个源码例子:http://support.zeus.com/zws/examples/2005/12/16/basic_authentication_isapi_filter

ISAPI extension负责最终写出HTML,这里有例子:http://support.zeus.com/zws/examples/2005/12/16/a_simple_page_counter_isapi_extension
------解决方案--------------------
楼主不会C++还问C++代码?那你会什么?delphi?
------解决方案--------------------
没下文了?
------解决方案--------------------
我觉得可行,加在 OnSendRawData中,我也正要做这样一个项目。