【问题标题】:Native IIS7.5 Module not running本机 IIS7.5 模块未运行
【发布时间】:2014-06-27 12:50:30
【问题描述】:

我创建了一个简单的CHttpModule,它为所有请求添加了一个自定义标头:

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

class AppendHeaderModule : public CHttpModule {
public:
    REQUEST_NOTIFICATION_STATUS
        OnBeginRequest(
        IN IHttpContext * pHttpContext,
        IN IHttpEventProvider * pProvider
        )
    {
        UNREFERENCED_PARAMETER(pProvider);

        PCSTR testHeaderName = "Foo";
        PCSTR testHeader = "bar";
        pHttpContext->GetResponse()->SetHeader(testHeaderName, testHeader, (USHORT)strlen(testHeader), true);

        return RQ_NOTIFICATION_CONTINUE;
    }

    VOID Terminate() {
        delete this;
    }

    AppendHeaderModule() { }
    ~AppendHeaderModule() { }
};

class AppendHeaderModuleFactory : public IHttpModuleFactory {
public:
    HRESULT
        GetHttpModule(
        OUT CHttpModule ** ppModule,
        IN IModuleAllocator * pAllocator
        )
    {
        UNREFERENCED_PARAMETER(pAllocator);

        AppendHeaderModule* pModule = new AppendHeaderModule;

        if (!pModule) {
            return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
        }
        else {
            *ppModule = pModule;
            pModule = NULL;
            return S_OK;
        }
    }

    void Terminate() {
        delete this;
    }
};


HRESULT __stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo * pModuleInfo,
IHttpServer * pGlobalInfo
)
{
    UNREFERENCED_PARAMETER(dwServerVersion);
    UNREFERENCED_PARAMETER(pGlobalInfo);

    AppendHeaderModuleFactory* pModule = new AppendHeaderModuleFactory;
    if (pModule == NULL) 
        return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);

    return pModuleInfo->SetRequestNotifications(pModule, RQ_BEGIN_REQUEST, 0);
}

我已将其复制到C:\Windows\System32\inetsrv,注册了模块并将其添加到列表中。但是,我在我的任何请求中都没有看到额外的标头。我创建了一个类似的托管模块,将它安装到 GAC,注册它,它工作正常。但是这个原生模块似乎什么也没做。是否需要其他步骤才能让原生模块处理请求?

另外,我不确定这是否重要,但请求是针对 ASP.NET 站点发出的。本机处理程序不能为 ASP.NET 运行吗?

【问题讨论】:

    标签: c++ http http-headers iis-7.5 ihttpmodule


    【解决方案1】:

    如果模块是 32 位模块,您需要在您的网站的应用程序池中启用 32 位应用程序。转到应用程序池,为您的网站选择池,高级设置并将“启用 32 位应用程序”设置为 TRUE。

    【讨论】:

      猜你喜欢
      • 2021-08-07
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 2012-07-16
      • 2019-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多