다음을 통해 공유


IMapHandlerProvider::SetScriptMap 메서드

현재 컨텍스트에 사용할 IScriptMapInfo 인터페이스를 지정합니다.

구문

virtual VOID SetScriptMap(  
   IScriptMapInfo* pScriptMap  
) = 0;  

매개 변수

pScriptMap
IScriptMapInfo 인터페이스에 대한 포인터입니다.

반환 값

VOID.

설명

메서드 SetScriptMap 를 사용하면 HTTP 모듈에서 IIS가 현재 컨텍스트 내에서 요청을 처리할 때 사용할 인터페이스를 지정할 IScriptMapInfo 수 있습니다. 예를 들어 사용자 지정 IScriptMapInfo 인터페이스를 만들고 웹 클라이언트가 웹 사이트에서 특정 리소스를 요청하는 경우 IIS가 해당 인터페이스를 사용하여 현재 요청을 처리하도록 지정할 수 있습니다.

예제

다음 예제 코드에서는 사용자 지정 IScriptMapInfo 인터페이스를 만드는 HTTP 모듈을 만드는 방법을 보여 줍니다. 모듈은 메서드를 SetScriptMap 사용하여 IIS가 사용자 지정 인터페이스를 사용하여 현재 요청을 처리한 다음 종료하도록 지정합니다.

#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>

// Create a global variable to store the response buffer limit.
DWORD g_dwResponseBufferLimit;
// Create a global pointer that will hold the path to the script processor.
WCHAR * g_pwszDllPath;

// Define a custom IScriptMapInfo interface.
class CScriptMapInfo : public IScriptMapInfo
{
public:
    PCSTR GetAllowedVerbs( VOID ) const
    {
        // Indicate that all verbs are allowed.
        return "*\0\0";
    }
    BOOL GetAllowPathInfoForScriptMappings( VOID ) const
    {
        // Indicate that path info for script mapping is not allowed.
        return FALSE;
    }
    BOOL GetIsStarScriptMap( VOID ) const
    {
        // Indicate that the script map handler is not a wildcard mapping.
        return FALSE;
    }
    PCWSTR GetManagedType( OUT DWORD * pcchManagedType = NULL ) const
    {
        // Return the managed type for this script map handler.
        if (pcchManagedType != NULL) *pcchManagedType = 0;
        return L"";
    }
    PCWSTR GetModules( OUT DWORD * pcchModules = NULL ) const
    {
        // Return the modules for this script map handler.
        if (pcchModules != NULL) *pcchModules = (DWORD)wcslen(L"IsapiModule");
        return L"IsapiModule";
    }
    PCWSTR GetName( VOID ) const
    {
        // Return the name of the example script map.
        return L"ScriptMapInfoExample";
    }
    PCWSTR GetPath( VOID ) const
    {
        // Return that this script map handler is valid for all paths.
        return L"*";
    }
    DWORD  GetRequiredAccess( VOID ) const
    {
        // Return a "read" access requirement.
        return 1;
    }
    DWORD GetResponseBufferLimit( VOID ) const
    {
        // Return the response buffer limit.
        return g_dwResponseBufferLimit;
    }
    DWORD GetResourceType( VOID ) const
    {
        // Return an "unspecified" resource type.
        return 3;
    }
    PCWSTR GetScriptProcessor( OUT DWORD * pcchScriptProcessor = NULL ) const
    {
        // Return the length of the script processor.
        if (pcchScriptProcessor != NULL)
            *pcchScriptProcessor = (DWORD)wcslen(g_pwszDllPath);
        // Return the path of the script processor.
        return g_pwszDllPath;
    }
};

// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
    REQUEST_NOTIFICATION_STATUS
    OnBeginRequest(
        IN IHttpContext * pHttpContext,
        IN IHttpEventProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );

        // Retrieve the response buffer limit and update the global variable.
        g_dwResponseBufferLimit =
            pHttpContext->GetScriptMap()->GetResponseBufferLimit();

        // Retrieve a chunk of memory from the context object.
        g_pwszDllPath = (WCHAR*)pHttpContext->AllocateRequestMemory(
            MAX_PATH*sizeof(WCHAR));

        // Test for an error.
        if (NULL == g_pwszDllPath)
        {
            // Return an error condition and exit.
            pHttpContext->GetResponse()->SetStatus(
                500,"",0,HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY ));
            return RQ_NOTIFICATION_FINISH_REQUEST;
        }
        else
        {
            // Define the maximum size of the path array.
            DWORD nSize = MAX_PATH*sizeof(WCHAR);
            // Retrieve the path of the Inetsrv folder.
            nSize = ::ExpandEnvironmentStringsW(
                L"%windir%\\system32\\inetsrv",g_pwszDllPath,nSize);
            // Exit if the path of the Inetsrv folder cannot be determined.
            if (nSize == 0)
            {
                // Clear the DLL path.
                wcscpy_s(g_pwszDllPath,MAX_PATH,L"");
            }
            else
            {
                // Append the Asp.dll file name to the Inetsrv path.
                wcscat_s(g_pwszDllPath,MAX_PATH,L"\\asp.dll");
            }
        }

        // Return processing to the pipeline.
        return RQ_NOTIFICATION_CONTINUE;
    }

    REQUEST_NOTIFICATION_STATUS
    OnMapRequestHandler(
        IN IHttpContext * pHttpContext,
        IN IMapHandlerProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pHttpContext );

        // Create a custom IScriptMapInfo interface.
        CScriptMapInfo * pScriptMapInfo = new CScriptMapInfo;

        // Test for an error.
        if (!pScriptMapInfo)
        {
            // Set the error condition.
            pProvider->SetErrorStatus(HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY ));
        }
        else
        {
            // Specify the custom IScriptMapInfo interface.
            pProvider->SetScriptMap(pScriptMapInfo);
        }

        // Return processing to the pipeline.
        return RQ_NOTIFICATION_CONTINUE;
    }
};

// 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 );

    // Initialize the global response buffer limit variable.
    g_dwResponseBufferLimit = 0;

    // Set the request notifications and exit.
    return pModuleInfo->SetRequestNotifications(
        new MyHttpModuleFactory,
        RQ_BEGIN_REQUEST | RQ_MAP_REQUEST_HANDLER,
        0
    );
}

모듈은 RegisterModule 함수를 내보내야 합니다. 프로젝트에 대한 모듈 정의(.def) 파일을 만들어 이 함수를 내보내거나 스위치를 사용하여 모듈을 /EXPORT:RegisterModule 컴파일할 수 있습니다. 자세한 내용은 연습: 네이티브 코드를 사용하여 Request-Level HTTP 모듈 만들기를 참조하세요.

필요에 따라 각 함수에 대한 호출 규칙을 명시적으로 선언하는 대신 호출 규칙을 사용하여 __stdcall (/Gz) 코드를 컴파일할 수 있습니다.

요구 사항

형식 Description
클라이언트 - 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

참고 항목

IMapHandlerProvider 인터페이스