Freigeben über


IMapPathProvider::SetPhysicalPath-Methode

Legt die Zuordnung des physischen Pfads für die aktuelle Anforderung fest.

Syntax

virtual HRESULT SetPhysicalPath(  
   PCWSTR pszPhysicalPath,  
   DWORD cchPhysicalPath  
) = 0;  

Parameter

pszPhysicalPath
[IN] Ein Zeiger auf eine Zeichenfolge, die den festzulegenden physischen Pfad enthält.

cchPhysicalPath
[IN] Ein DWORD , der die Länge der pszPhysicalPath Zeichenfolge enthält.

Rückgabewert

HRESULT. Mögliches Werte (aber nicht die Einzigen) sind die in der folgenden Tabelle.

Wert BESCHREIBUNG
S_OK Gibt an, dass der Vorgang erfolgreich war.
ERROR_INVALID_PARAMETER Gibt an, dass in einem der Parameter ein ungültiger Wert übergeben wurde.

Bemerkungen

Die SetPhysicalPath -Methode ändert den zugeordneten Pfad für Anforderungen. Beispielsweise kann ein HTTP-Modul die SetPhysicalPath -Methode verwenden, um den Standardinhaltsspeicherort für Anforderungen in einen anderen Pfad als den in der ApplicationHost.config-Datei konfigurierten Pfad zu ändern.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie Sie mit der SetPhysicalPath -Methode ein HTTP-Modul erstellen, das den physischen Standardpfad für die aktuelle Anforderung in C:\Temp ändert.

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

// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
    REQUEST_NOTIFICATION_STATUS
    OnMapPath(
        IN IHttpContext * pHttpContext,
        IN IMapPathProvider * pProvider
    )
    {
        // Create an HRESULT to receive return values from methods.
        HRESULT hr;

        // Buffer that contains the physical path to set.
        WCHAR wszPhysicalPath[] = L"C:\\TEMP";

        // Set the physical path.
        hr = pProvider->SetPhysicalPath(
            wszPhysicalPath,(DWORD)wcslen(wszPhysicalPath));
        
        // Test for an error.
        if (FAILED(hr))
        {
            // Set the error status.
            pProvider->SetErrorStatus( hr );
            // End additional processing.
            return RQ_NOTIFICATION_FINISH_REQUEST;
        }

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

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

Ihr Modul muss die RegisterModule-Funktion exportieren. Sie können diese Funktion exportieren, indem Sie eine Moduldefinitionsdatei (.def) für Ihr Projekt erstellen, oder Sie können das Modul mithilfe des Schalters /EXPORT:RegisterModule kompilieren. Weitere Informationen finden Sie unter Exemplarische Vorgehensweise: Erstellen eines Request-Level HTTP-Moduls mithilfe von nativem Code.

Sie können den Code optional kompilieren, indem Sie die __stdcall (/Gz) Aufrufkonvention verwenden, anstatt die Aufrufkonvention für jede Funktion explizit zu deklarieren.

Anforderungen

type BESCHREIBUNG
Client – IIS 7.0 unter Windows Vista
– IIS 7.5 unter Windows 7
– IIS 8.0 unter Windows 8
– IIS 10.0 unter Windows 10
Server – IIS 7.0 unter Windows Server 2008
– IIS 7.5 unter Windows Server 2008 R2
– IIS 8.0 unter Windows Server 2012
– IIS 8.5 unter Windows Server 2012 R2
– IIS 10.0 unter Windows Server 2016
Produkt – 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

Weitere Informationen

IMapPathProvider-Schnittstelle