Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Mengembalikan parameter panggilan fungsi dinamis yang menyebabkan peristiwa.
Sintaks
virtual PCWSTR GetFunctionParameters(
VOID
) const = 0;
Parameter
Metode ini tidak memerlukan parameter.
Tampilkan Nilai
Penunjuk ke string Unicode yang dihentikan null konstan yang berisi parameter panggilan fungsi dinamis yang menyebabkan peristiwa.
Keterangan
Kelas turunan CGlobalModule yang mendaftar untuk peristiwa GL_RSCA_QUERY menerima pointer IGlobalRscaQueryProvider sebagai parameter pada metode CGlobalModule::OnGlobalRSCAQueryvirtual . Anda kemudian dapat mengambil parameter fungsi dengan memanggil GetFunctionParameters metode pada pointer IGlobalRSCAQueryProvider .
Nilai GetFunctionParameters pengembalian metode tergantung pada implementasi. Anda harus menggunakan informasi berikut sebagai pedoman, tetapi mungkin tidak benar dalam semua skenario:
Implementer default antarmuka IProtocolManager, IPmCustomActions, IPmHealthAndIdleMonitor, dan IPmListenerChannelManager menimbulkan peristiwa saat Anda memanggil metode IRSCA_WorkerProcess::EnumerateAppDomains dan IRSCA_AppDomain::Unload . Metode ini masing-masing dipetakan ke nilai PMH_App_Domain_Enum_V1 dan PMH_App_Domain_Unload_V1, yang dikembalikan saat Anda memanggil metode GetFunctionName . Parameter fungsi ini, pada gilirannya, dikembalikan saat Anda memanggil
GetFunctionParameters.Pelaksana
IGlobalRSCAQueryProvidermenerima nama fungsi dan nilai parameter fungsi sebagai string ketika salah satu peristiwa IRSCA_AppDomain dinaikkan, dan pelaksana memegang referensi ke string ini. Jika string adalah NULL,GetFunctionParametersmengembalikan string kosong. Jika tidak,GetFunctionParametersmengembalikan penunjuk ke string bersama ini.
Catatan untuk Pelaksana
IGlobalRSCAQueryProvider pelaksana bertanggung jawab atas manajemen memori dengan data ini; oleh karena itu, IGlobalRSCAQueryProvider pelaksana yang menggunakan alokasi memori dinamis harus melepaskan atau memanggil delete penunjuk PCWSTR ketika tidak lagi diperlukan.
Catatan untuk Penelepon
IGlobalRSCAQueryProvider pelaksana bertanggung jawab atas manajemen memori dengan data ini; oleh karena itu, IGlobalRSCAQueryProvider klien tidak boleh merilis atau memanggil delete penunjuk yang PCWSTR dikembalikan ketika data ini tidak lagi diperlukan. Selain itu, klien tidak boleh mentransmisikan data ini ke penunjuk yang bukan const atau mengubah status memori yang direferensikan oleh ini PCWSTR, karena pelanggaran akses akan dilemparkan atau data akan menjadi tidak valid.
Contoh
Contoh kode berikut menunjukkan cara membuat modul global yang mendengarkan peristiwa GL_RSCA_QUERY lalu menulis informasi parameter fungsi ke Pemampil Peristiwa.
Perhatian
IIS 7 menghasilkan sejumlah besar peristiwa di Penampil Peristiwa. Untuk menghindari kesalahan luapan log di lingkungan produksi, Anda umumnya harus menghindari penulisan informasi cache ke log peristiwa. Untuk tujuan demonstrasi, contoh kode ini menulis entri ke Penampil Peristiwa hanya dalam mode debug.
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <tchar.h>
#include <httpserv.h>
#include <string>
using namespace std;
// The CConvert class mirrors the Convert class that is
// defined in the .NET Framework. It converts primitives
// and other data types to wstring types.
class CConvert
{
public:
// The ToByteString converts a double-byte
// character string to a single-byte string.
// str: the double-byte string to convert.
// return: a single-byte string copied from str.
static string ToByteString(const wstring& str)
{
// Get the length of the
// double-byte string.
size_t length = str.length();
// Create a temporary char pointer.
char* byteChar = new char[length+1];
byteChar[0] = '\0';
// Copy the double-byte character string
// into the single-byte string.
size_t charsReturned = 0;
wcstombs_s(&charsReturned, byteChar,
length+1, str.c_str(), length+1);
// Create a string to return.
string retString = byteChar;
// Delete the temporary string and
// set that string to NULL.
delete[] byteChar;
byteChar = NULL;
// Return the single-byte string.
return retString;
}
};
// The CEventWriter class writes XML
// documents and strings to the event log.
class CEventWriter
{
public:
// Creates the CEventWriter class.
// name: the name of the
// event log to open.
CEventWriter(const wstring& name)
{
#ifdef UNICODE
m_eventLog = RegisterEventSource(NULL, name.c_str());
#else
string multiName = CConvert::ToByteString(name);
m_eventLog = RegisterEventSource(NULL, multiName.c_str());
#endif
}
// Creates the destructor for the
// CEventWriter class. This destructor
// closes the HANDLE to the event
// log if that HANDLE is open.
virtual ~CEventWriter()
{
// If the HANDLE to the event
// log is open, close it.
if (NULL != m_eventLog)
{
// Deregister the event log HANDLE.
DeregisterEventSource(m_eventLog);
// Set the HANDLE to NULL.
m_eventLog = NULL;
}
}
// The ReportInfo method writes
// a wstring to the event log.
// info: the wstring to write.
// return: true if the event log is written.
BOOL ReportInfo(const wstring& info)
{
return ReportEvent(EVENTLOG_INFORMATION_TYPE, info);
}
protected:
// The ReportEvent method accepts an event type
// and a wstring, and attempts to write that
// event to the event log.
// type: the type of the event.
// data: the wstring to write to the event log.
// return: true if the event log is written;
// otherwise, false.
BOOL ReportEvent(WORD type, const wstring& data)
{
// If the m_eventLog HANDLE
// is NULL, return false.
if (NULL == m_eventLog)
{
return FALSE;
}
#ifndef _DEBUG
// If the current build is not debug,
// return so the event log is not written.
return TRUE;
#endif
#ifdef UNICODE
// The unicode version of the ReportEvent
// method requires double-byte strings.
PCWSTR arr[1];
arr[0] = data.c_str();
return ::ReportEvent(m_eventLog,
type,
0, 0, NULL, 1,
0, arr, (void*)arr);
#else
// The non-unicode version of the ReportEvent
// method requires single-byte strings.
string multiByte =
CConvert::ToByteString(data);
LPCSTR arr[1];
arr[0] = multiByte.c_str();
return ::ReportEvent(m_eventLog,
type,
0, 0, NULL, 1,
0, arr, (void*)arr);
#endif
}
private:
// Specify the HANDLE to the
// event log for writing.
HANDLE m_eventLog;
};
// The CRSCAGlobalModule class creates the CGlobalModule
// class and registers for GL_RSCA_QUERY and events.
class CRSCAGlobalModule : public CGlobalModule
{
public:
// Creates the destructor for the
// CGlobalCacheModule class.
virtual ~CRSCAGlobalModule()
{
}
// The RegisterGlobalModule method creates and registers
// a new CRSCAGlobalModule for GL_RSCA_QUERY events.
// dwServerVersion: the current server version.
// pModuleInfo: the current IHttpModuleRegistrationInfo pointer.
// pGlobalInfo: the current IHttpServer pointer.
// return: E_INVALIDARG if the IHttpServer pointer
// is NULL; ERROR_NOT_ENOUGH_MEMORY if the heap is out of
// memory; otherwise, the value from the call to the
// SetGlobalNotifications method on the pModuleInfo pointer.
static HRESULT RegisterGlobalModule
(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo* pModuleInfo,
IHttpServer* pGlobalInfo
)
{
// The pGlobalInfo parmeter must be
// non-NULL because the constructor
// for the CGlobalCacheModule class
// requires a non-NULL pointer to a
// valid IHttpServer pointer.
if (NULL == pGlobalInfo)
{
return E_INVALIDARG;
}
// Create a new CGlobalCacheModule pointer.
CRSCAGlobalModule* rscaModule =
new CRSCAGlobalModule();
// Return an out-of-memory error
// if the traceModule is NULL
// after the call to the new operator.
if (NULL == rscaModule)
{
return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
}
// Attempt to set global notification
// for GL_RSCA_QUERY events by using
// the rscaModule as a listener.
HRESULT hr = pModuleInfo->SetGlobalNotifications
(rscaModule, GL_RSCA_QUERY);
// Return the HRESULT from the call to
// the SetGlobalNotifications method.
return hr;
}
// The OnGlobalRSCAQuery method is the event
// handler method for the GL_RSCA_QUERY event.
// pProvider: the IGlobalRSCAQueryProvider pointer.
// return: GL_NOTIFICATION_CONTINUE.
virtual GLOBAL_NOTIFICATION_STATUS OnGlobalRSCAQuery
(
IN IGlobalRSCAQueryProvider* pProvider
)
{
// Return GL_NOTIFICATION_CONTINUE if the
// IGlobalRSCAQueryProvider pointer is NULL.
if (NULL == pProvider)
{
return GL_NOTIFICATION_CONTINUE;
}
// Get the parameters from the
// IGlobalRSCAQueryProvider pointer.
wstring parameters =
pProvider->GetFunctionParameters();
// Write the parameter information
// to the event writer.
m_eventWriter.ReportInfo
(L"Parameters: " + parameters);
// Return GL_NOTIFICATION_CONTINUE so
// other listeners will receive this event.
return GL_NOTIFICATION_CONTINUE;
}
// The Terminate method is a pure virtual
// method that all non-abstract CGlobalModule
// classes must implement. Calls delete on this.
virtual VOID Terminate(VOID)
{
delete this;
}
protected:
// Creates the CRSCAGlobalModule class.
// Initializes the CEventWriter to write
// to the event log using the IISADMIN key.
CRSCAGlobalModule() : m_eventWriter(L"IISADMIN")
{
}
private:
// Specify the CEventWriter writer.
CEventWriter m_eventWriter;
};
// The RegisterModule method is the
// main entry point for the DLL.
// dwServerVersion: the current server version.
// pModuleInfo: the current
// IHttpModuleRegistrationInfo pointer.
// pGlobalInfo: the current IHttpServer pointer.
// return: the value returned by calling the
// CRSCAGlobalModule::RegisterGlobalModule
// method.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo* pModuleInfo,
IHttpServer* pGlobalInfo
)
{
// Call the static method for initialization.
return CRSCAGlobalModule::RegisterGlobalModule
(dwServerVersion,
pModuleInfo,
pGlobalInfo);
}
Untuk informasi selengkapnya tentang cara membuat dan menyebarkan modul DLL asli, lihat Panduan: Membuat Modul HTTP Request-Level Dengan Menggunakan Kode Asli.
Kode di atas menulis peristiwa ke log aplikasi Penampil Peristiwa, di mana kotak Data berisi string yang mirip dengan yang berikut ini:
Parameters:
Anda dapat secara opsional mengkompilasi kode dengan menggunakan konvensi panggilan __stdcall (/Gz) alih-alih secara eksplisit mendeklarasikan konvensi panggilan untuk setiap fungsi.
Persyaratan
| Jenis | Deskripsi |
|---|---|
| Klien | - IIS 7.0 di Windows Vista - IIS 7.5 di Windows 7 - IIS 8.0 di Windows 8 - IIS 10.0 pada Windows 10 |
| Server | - IIS 7.0 di Windows Server 2008 - IIS 7.5 di Windows Server 2008 R2 - IIS 8.0 di Windows Server 2012 - IIS 8.5 di Windows Server 2012 R2 - IIS 10.0 di Windows Server 2016 |
| Produk | - 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 |