IHttpContext::D isableNotifications 方法
禁用当前模块中针对此请求挂起的特定通知。
语法
virtual VOID DisableNotifications(
IN DWORD dwNotifications,
IN DWORD dwPostNotifications
) = 0;
parameters
dwNotifications
[IN]一个 DWORD
,它包含一个位掩码,该掩码指定要为此模块禁用的请求通知。
dwPostNotifications
[IN]一个 DWORD
,它包含一个位掩码,该掩码指定要为此模块禁用的请求后通知。
返回值
VOID
.
注解
可以使用 DisableNotifications
方法指定要为当前请求禁用哪些通知或请求后通知。 例如,如果要创建的模块已注册 RQ_AUTHENTICATE_REQUEST 并 RQ_AUTHORIZE_REQUEST 通知,则可以将模块配置为根据通知中处理的条件忽略 RQ_AUTHORIZE_REQUEST
通知 RQ_AUTHENTICATE_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)
而不是为每个函数显式声明调用约定。
要求
类型 | 说明 |
---|---|
客户端 | - 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 |
另请参阅
IHttpContext 接口
IHttpContext::GetIsLastNotification 方法
IHttpContext::GetNextNotification 方法
PFN_REGISTERMODULE 函数