REQUEST_NOTIFICATION_STATUS 枚举

定义请求级别通知的返回值。

语法

typedef enum REQUEST_NOTIFICATION_STATUS{  
   RQ_NOTIFICATION_CONTINUE,  
   RQ_NOTIFICATION_PENDING,  
   RQ_NOTIFICATION_FINISH_REQUEST  
};  

成员

成员名称 说明
RQ_NOTIFICATION_CONTINUE 指示 IIS 应继续处理其他请求级通知。
RQ_NOTIFICATION_PENDING 指示异步通知处于挂起状态,并将请求级处理返回到 IIS。
RQ_NOTIFICATION_FINISH_REQUEST 指示 IIS 已完成处理请求级通知,不应处理任何其他请求级通知。

备注

枚举的成员 REQUEST_NOTIFICATION_STATUS 用作请求级别通知的返回值,成员有助于控制集成请求处理管道中的进程流。 例如,从请求级通知处理程序返回 RQ_NOTIFICATION_CONTINUE 指示 IIS 继续处理其他请求级通知,而从请求级通知处理程序返回 RQ_NOTIFICATION_FINISH_REQUEST 会通知 IIS 请求级处理已完成,IIS 不应处理其他请求级通知。 发生错误时,实现请求处理的模块应返回 RQ_NOTIFICATION_FINISH_REQUEST

示例

以下示例实现处理程序 RQ_BEGIN_REQUEST 。 如果请求不是 HTML 文件,则示例将返回 RQ_NOTIFICATION_CONTINUE 并正常处理。 当计数器值为零余数时,请求的文件将替换为 由 IHttpResponse::WriteEntityChunkByReference 方法返回的字符串,该示例返回 RQ_NOTIFICATION_FINISH_REQUEST。 如果发生错误,该示例将记录错误并返回 RQ_NOTIFICATION_FINISH_REQUEST

REQUEST_NOTIFICATION_STATUS
CMyHttpModule::OnBeginRequest(
    IHttpContext*       pHttpContext,
    IHttpEventProvider* pProvider
)
{
    HRESULT hr;

    static long cnt;
    InterlockedIncrement(&cnt);  // keep track of how many times we are called
    cnt++;

    IHttpRequest *pRequest = pHttpContext->GetRequest();
    PCWSTR url = pRequest->GetRawHttpRequest()->CookedUrl.pAbsPath;
    OutputDebugStringW(url);

    // return unless requesting a HTML file

    if (!wcsstr(url, L".htm"))
        return RQ_NOTIFICATION_CONTINUE;

    IHttpResponse * pHttpResponse = pHttpContext->GetResponse();

    // Return most times so we can still view content
    if ((cnt % 5) || pHttpResponse == NULL)
        return RQ_NOTIFICATION_CONTINUE;

    TRC_MSG_FULL("HTML  cnt = " << cnt);

    static int insertPosCnt;
    int insertPos = ++insertPosCnt % 2 - 1;    // toggle between 0 and -1

    // Use ostringstream to create some dynamic content
    std::ostringstream os;

    os << "<p /> first chunk  callback count = " << cnt
        << " insertPos = " << insertPos << "<br />";

    // 
    // WECbyRefChunk does all the work of inserting data into the response
    //

    hr = WECbyRefChunk(os, pHttpContext, pProvider, insertPos);
    if (FAILED(hr))
        return RQ_NOTIFICATION_FINISH_REQUEST;

    os << "<br /> <b> Adding 2nd chunk in Bold </b> File insertPos = " << insertPos;
    hr = WECbyRefChunk(os, pHttpContext, pProvider, insertPos);
    if (FAILED(hr))
        return RQ_NOTIFICATION_FINISH_REQUEST;

    os << " <p /> Last (3rd) Chunk added with default append chunk  GetCurrentThreadId = "
        << GetCurrentThreadId();

    // any errors will be logged/handled in  WECbyRefChunk
    WECbyRefChunk(os, pHttpContext, pProvider);

    // End additional processing, not because of error, but so another request
    // (from a GIF or .css style sheet on the same HTML page)
    // doesn't wipe out our WriteEntityChunkByReference. We can also get the
    // WriteEntityChunkByReference prepended to our normal HTML page. 

    return RQ_NOTIFICATION_FINISH_REQUEST;

}
HRESULT hr = S_OK;

IHttpTraceContext * pTraceContext = pHttpContext->GetTraceContext();
hr = My_Events::My_COMPLETION::RaiseEvent(pTraceContext, InsertPosition);
if (FAILED(hr)) {
    LOG_ERR_HR(hr, "RaiseEvent");
    return hr;
}

要求

类型 说明
客户端 - Windows Vista 上的 IIS 7.0
- Windows 7 上的 IIS 7.5
- Windows 8 上的 IIS 8.0
- Windows 10 上的 IIS 10.0
服务器 - Windows Server 2008 上的 IIS 7.0
- Windows Server 2008 R2 上的 IIS 7.5
- Windows Server 2012 上的 IIS 8.0
- Windows Server 2012 R2 上的 IIS 8.5
- Windows Server 2016 上的 IIS 10.0
产品 - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
- IIS Express 7.5、IIS Express 8.0、IIS Express 10.0
Header Httpserv.h

另请参阅

Web 服务器核心枚举
GLOBAL_NOTIFICATION_STATUS 枚举