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;
}
規格需求
類型 | 描述 |
---|---|
Client | - 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 |
標頭 | Httpserv.h |