CHttpModule::OnReadEntity 方法
表示将处理 ReadEntity
事件的方法,该事件在操作从请求缓冲区读取数据时发生。
语法
virtual REQUEST_NOTIFICATION_STATUS OnReadEntity(
IN IHttpContext* pHttpContext,
IN IReadEntityProvider* pProvider
);
parameters
pHttpContext
[IN]指向 IHttpContext 接口的指针。
pProvider
[IN]指向 IReadEntityProvider 接口的 指针。
返回值
备注
当请求级模块注册 RQ_READ_ENTITY 事件通知时,当操作从请求缓冲区读取数据时,IIS 将调用模块 OnReadEntity
的 方法。
注意
请求级模块可以通过在模块的 PostReadEntity
RegisterModule 函数中注册 来RQ_READ_ENTITY
注册事件通知。
示例
以下示例演示如何创建注册事件通知的请求级 HTTP 模块 RQ_READ_ENTITY
。 当 IIS 从请求缓冲区读取数据时,它将调用示例模块的 OnReadEntity
方法。 执行帖子的简单 HTML 或 ASP.NET 页将导致示例代码运行。
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
// Process an RQ_READ_ENTITY event.
REQUEST_NOTIFICATION_STATUS
OnReadEntity(
IN IHttpContext * pHttpContext,
IN IReadEntityProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pHttpContext );
UNREFERENCED_PARAMETER( pProvider );
WriteEventViewerLog("OnReadEntity");
return RQ_NOTIFICATION_CONTINUE;
}
MyHttpModule()
{
// Open a handle to the Event Viewer.
m_hEventLog = RegisterEventSource( NULL,"IISADMIN" );
}
~MyHttpModule()
{
// Test whether the handle for the Event Viewer is open.
if (NULL != m_hEventLog)
{
// Close the handle to the Event Viewer.
DeregisterEventSource( m_hEventLog );
m_hEventLog = NULL;
}
}
private:
// Create a handle for the event viewer.
HANDLE m_hEventLog;
// Define a method that writes to the Event Viewer.
BOOL WriteEventViewerLog(LPCSTR szNotification)
{
// Test whether the handle for the Event Viewer is open.
if (NULL != m_hEventLog)
{
// Write any strings to the Event Viewer and return.
return ReportEvent(
m_hEventLog,
EVENTLOG_INFORMATION_TYPE, 0, 0,
NULL, 1, 0, &szNotification, NULL );
}
return FALSE;
}
};
// 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(
// Specify the class factory.
new MyHttpModuleFactory,
// Specify the event notifications.
RQ_READ_ENTITY,
// Specify no post-event notifications.
0
);
}
要求
类型 | 说明 |
---|---|
客户端 | - 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 |