IScriptMapInfo::GetAllowPathInfoForScriptMappings 方法

检索一个值,该值指示脚本映射处理程序是否将 allowPathInfo 属性设置为 true

语法

virtual BOOL GetAllowPathInfoForScriptMappings(
   VOID
) const = 0;

参数

此方法不采用参数。

返回值

trueallowPathInfo如果脚本映射的属性设置为 true,则为 ;否则为 false

备注

开发人员可以使用 GetAllowPathInfoForScriptMappings 方法检索一个值,该值指定 HTTP 处理程序在处理请求时是否配置为允许 PathInfo 数据。 PathInfo 是指可能遵循统一资源标识符 (URI) 中文件名和扩展名的其他路径信息。 例如,如果请求 URI http://localhost/test.dll/myinfo,则该 URI 的 PathInfo 部分为 /myinfo。

若要配置允许使用 PathInfo 信息的 HTTP 处理程序,请将 ApplicationHost.config 文件中 HTTP 处理程序的 属性true设置为 allowPathInfo 。 例如,ApplicationHost.config 文件中 Internet 服务器 API (ISAPI) DLL 的配置部分可能类似于以下示例:

<add name="ISAPI-dll"
    path="*.dll"
    verb="*"
    modules="IsapiModule"
    resourceType="File"
    requireAccess="Execute"
    allowPathInfo="true" />

此示例为 ISAPI DLL 启用 PathInfo 数据。 同样,将 allowPathInfo 属性设置为 false 以禁用 PathInfo 数据。

示例

下面的代码示例演示如何使用 GetAllowPathInfoForScriptMappings 方法创建一个 HTTP 模块,该模块检索指向 IScriptMapInfo 接口的指针。 然后,该示例使用 GetAllowPathInfoForScriptMappings 方法检索一个值,该值指示是否为脚本映射启用 PathInfo 数据。 该模块将结果返回到 Web 客户端,然后退出。

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

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

        // Retrieve the IScriptMapInfo interface.
        IScriptMapInfo * pScriptMapInfo = pHttpContext->GetScriptMap();

        // Test for an error.
        if (NULL != pScriptMapInfo)
        {
            // Retrieve the path info status.
            BOOL fPathInfo = pScriptMapInfo->GetAllowPathInfoForScriptMappings();
            // Return the path info status to the client.
            WriteResponseMessage(pHttpContext,"PathInfo Allowed: ",
                (TRUE == fPathInfo) ? "Yes" : "No");
            // End additional processing.
            return RQ_NOTIFICATION_FINISH_REQUEST;
        }

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

private:

    // Create a utility method that inserts a name/value pair into the response.
    HRESULT WriteResponseMessage(
        IHttpContext * pHttpContext,
        PCSTR pszName,
        PCSTR pszValue
    )
    {
        // Create an HRESULT to receive return values from methods.
        HRESULT hr;
        
        // Create a data chunk.
        HTTP_DATA_CHUNK dataChunk;
        // Set the chunk to a chunk in memory.
        dataChunk.DataChunkType = HttpDataChunkFromMemory;
        // Buffer for bytes written of data chunk.
        DWORD cbSent;

        // Set the chunk to the first buffer.
        dataChunk.FromMemory.pBuffer =
            (PVOID) pszName;
        // Set the chunk size to the first buffer size.
        dataChunk.FromMemory.BufferLength =
            (USHORT) strlen(pszName);
        // Insert the data chunk into the response.
        hr = pHttpContext->GetResponse()->WriteEntityChunks(
            &dataChunk,1,FALSE,TRUE,&cbSent);
        // Test for an error.
        if (FAILED(hr))
        {
            // Return the error status.
            return hr;
        }

        // Set the chunk to the second buffer.
        dataChunk.FromMemory.pBuffer =
            (PVOID) pszValue;
        // Set the chunk size to the second buffer size.
        dataChunk.FromMemory.BufferLength =
            (USHORT) strlen(pszValue);
        // Insert the data chunk into the response.
        hr = pHttpContext->GetResponse()->WriteEntityChunks(
            &dataChunk,1,FALSE,TRUE,&cbSent);
        // Test for an error.
        if (FAILED(hr))
        {
            // Return the error status.
            return hr;
        }

        // Return a success status.
        return S_OK;
    }
};

// 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,
        0,
        RQ_MAP_REQUEST_HANDLER
    );
}

模块必须导出 RegisterModule 函数。 可以通过为项目创建模块定义 (.def) 文件导出此函数,也可以使用 开关编译模块 /EXPORT:RegisterModule 。 有关详细信息,请参阅 演练:使用本机代码创建Request-Level HTTP 模块

可以选择使用调用约定编译代码, __stdcall (/Gz) 而不是为每个函数显式声明调用约定。

要求

类型 说明
客户端 - 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

另请参阅