指出 IIS 是否會正常關閉任何目前擱置中的要求。
語法
virtual BOOL DrainRequestsGracefully(
VOID
) const = 0;
參數
此方法不會採用任何參數。
傳回值
true 如果 IIS 會正常關閉目前的要求,則為 ;否則為 false 。
備註
方法 DrainRequestsGracefully 會擷取 IIS 在關閉背景工作進程時關閉任何擱置要求的相關資訊。 例如,如果重新開機 IIS,方法會傳回 false , DrainRequestsGracefully 因為所有擱置的要求都會終止。 不過,如果回收應用程式集區,方法會傳回 true , DrainRequestsGracefully 因為關閉背景工作進程上的所有擱置要求都會正常關閉。
範例
下列程式碼範例示範如何建立執行下列工作的 HTTP 模組:
註冊 GL_STOP_LISTENING 通知。
建立包含OnGlobalStopListening方法的CGlobalModule類別。 這個方法會執行下列工作:
擷取 IIS 將使用 方法來關閉目前要求
DrainRequestsGracefully的狀態。格式化包含狀態資訊的字串。
將字串當做事件寫入事件檢視器的應用程式記錄檔。
CGlobalModule從記憶體中移除 類別,然後結束。
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// Create the module's global class.
class MyGlobalModule : public CGlobalModule
{
public:
// Process a GL_STOP_LISTENING notification.
GLOBAL_NOTIFICATION_STATUS
OnGlobalStopListening(
IN IGlobalStopListeningProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Create a string buffer.
char szBuffer[256] = "";
// Retrieve the Boolean value and format the string.
sprintf_s(szBuffer,255,"Drain Requests Gracefully: %s",
(TRUE==pProvider->DrainRequestsGracefully())?"Yes":"No");
// Write the string to the event viewer.
WriteEventViewerLog(szBuffer);
// Continue processing.
return GL_NOTIFICATION_CONTINUE;
}
VOID Terminate()
{
// Remove the class from memory.
delete this;
}
MyGlobalModule()
{
// Open a handle to the Event Viewer.
m_hEventLog = RegisterEventSource( NULL,"IISADMIN" );
}
~MyGlobalModule()
{
// 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 exported registration function.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo * pModuleInfo,
IHttpServer * pGlobalInfo
)
{
UNREFERENCED_PARAMETER( dwServerVersion );
UNREFERENCED_PARAMETER( pGlobalInfo );
// Create an instance of the global module class.
MyGlobalModule * pGlobalModule = new MyGlobalModule;
// Test for an error.
if (NULL == pGlobalModule)
{
return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
}
// Set the global notifications and exit.
return pModuleInfo->SetGlobalNotifications(
pGlobalModule, GL_STOP_LISTENING );
}
您的模組必須匯出 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 |