停用目前模組中此要求擱置的特定通知。
語法
virtual VOID DisableNotifications(
IN DWORD dwNotifications,
IN DWORD dwPostNotifications
) = 0;
參數
dwNotifications
[IN] DWORD ,包含位元遮罩,指定要針對此模組停用的要求通知。
dwPostNotifications
[IN] DWORD ,其中包含位元遮罩,指定要針對此模組停用的後續要求通知。
傳回值
VOID.
備註
您可以使用 DisableNotifications 方法來指定您要針對目前要求停用的通知或後續要求通知。 例如,如果您要建立的模組已註冊RQ_AUTHENTICATE_REQUEST和RQ_AUTHORIZE_REQUEST通知,則可以將模組設定為根據通知中 RQ_AUTHENTICATE_REQUEST 處理的條件忽略 RQ_AUTHORIZE_REQUEST 通知。
注意
只有目前要求和目前模組中的通知才能停用。 停用在其他模組中實作的通知的唯一方式,就是從模組傳回 RQ_NOTIFICATION_FINISH_REQUEST 。
注意
通知只能針對確定性事件停用;無法針對非決定性事件停用它們。 如需詳細資訊,請參閱 比較Native-Code和Managed-Code通知。
範例
下列範例示範如何使用 DisableNotifications 方法來建立 HTTP 模組,以停用目前要求的擱置 CHttpModule::OnPostBeginRequest 通知。
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
REQUEST_NOTIFICATION_STATUS
OnBeginRequest(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Clear the existing response.
pHttpContext->GetResponse()->Clear();
// Set the MIME type to plain text.
pHttpContext->GetResponse()->SetHeader(
HttpHeaderContentType,"text/plain",
(USHORT)strlen("text/plain"),TRUE);
// Return a message to the client to indiciate the notification.
WriteResponseMessage(pHttpContext,
"\nNotification: ","OnBeginRequest");
// Buffer to store the byte count.
DWORD cbSent = 0;
// Flush the response.
pHttpContext->GetResponse()->Flush(false,true,&cbSent,NULL);
// Specify which notifications to disable.
// (Defined in the Httpserv.h file.)
pHttpContext->DisableNotifications(RQ_BEGIN_REQUEST, 0);
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
REQUEST_NOTIFICATION_STATUS
OnPostBeginRequest(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Return a message to the client to indiciate the notification.
WriteResponseMessage(pHttpContext,
"\nNotification: ","OnPostBeginRequest");
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
REQUEST_NOTIFICATION_STATUS
OnAcquireRequestState(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Return a message to the client to indiciate the notification.
WriteResponseMessage(pHttpContext,
"\nNotification: ","OnAcquireRequestState");
// End additional processing.
return RQ_NOTIFICATION_FINISH_REQUEST;
}
private:
// Create a utility method that inserts a name/value pair into the response.
HRESULT WriteResponseMessage(
IHttpContext * pHttpContext,
PCSTR pszName,
PCSTR pszValue
)
{
// Create an HRESULT to receive return values from methods.
HRESULT hr;
// Create a data chunk.
HTTP_DATA_CHUNK dataChunk;
// Set the chunk to a chunk in memory.
dataChunk.DataChunkType = HttpDataChunkFromMemory;
// Buffer for bytes written of data chunk.
DWORD cbSent;
// Set the chunk to the first buffer.
dataChunk.FromMemory.pBuffer =
(PVOID) pszName;
// Set the chunk size to the first buffer size.
dataChunk.FromMemory.BufferLength =
(USHORT) strlen(pszName);
// Insert the data chunk into the response.
hr = pHttpContext->GetResponse()->WriteEntityChunks(
&dataChunk,1,FALSE,TRUE,&cbSent);
// Test for an error.
if (FAILED(hr))
{
// Return the error status.
return hr;
}
// Set the chunk to the second buffer.
dataChunk.FromMemory.pBuffer =
(PVOID) pszValue;
// Set the chunk size to the second buffer size.
dataChunk.FromMemory.BufferLength =
(USHORT) strlen(pszValue);
// Insert the data chunk into the response.
hr = pHttpContext->GetResponse()->WriteEntityChunks(
&dataChunk,1,FALSE,TRUE,&cbSent);
// Test for an error.
if (FAILED(hr))
{
// Return the error status.
return hr;
}
// Return a success status.
return S_OK;
}
};
// Create the module's class factory.
class MyHttpModuleFactory : public IHttpModuleFactory
{
public:
HRESULT
GetHttpModule(
OUT CHttpModule ** ppModule,
IN IModuleAllocator * pAllocator
)
{
UNREFERENCED_PARAMETER( pAllocator );
// Create a new instance.
MyHttpModule * pModule = new MyHttpModule;
// Test for an error.
if (!pModule)
{
// Return an error if the factory cannot create the instance.
return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
}
else
{
// Return a pointer to the module.
*ppModule = pModule;
pModule = NULL;
// Return a success status.
return S_OK;
}
}
void Terminate()
{
// Remove the class from memory.
delete this;
}
};
// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo * pModuleInfo,
IHttpServer * pGlobalInfo
)
{
UNREFERENCED_PARAMETER( dwServerVersion );
UNREFERENCED_PARAMETER( pGlobalInfo );
// Set the request notifications and exit.
return pModuleInfo->SetRequestNotifications(
new MyHttpModuleFactory,
RQ_BEGIN_REQUEST | RQ_ACQUIRE_REQUEST_STATE,
RQ_BEGIN_REQUEST
);
}
您的模組必須匯出 RegisterModule 函式 。 您可以為專案建立模組定義 (.def) 檔案,或使用 參數編譯模組 /EXPORT:RegisterModule 來匯出此函式。 如需詳細資訊,請參閱逐步解說 :使用機器碼建立Request-Level HTTP 模組。
您可以選擇性地使用呼叫慣例編譯器代碼, __stdcall (/Gz) 而不是明確宣告每個函式的呼叫慣例。
規格需求
| 類型 | 描述 |
|---|---|
| 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 |
另請參閱
IHttpCoNtext 介面
IHttpCoNtext::GetIsLastNotification 方法
IHttpCoNtext::GetNextNotification 方法
PFN_REGISTERMODULE函式