如何在 C# 中操作标头然后继续处理它?

发布于 2024-08-25 09:18:14 字数 965 浏览 6 评论 0原文


我想替换在 IIS6 上运行的旧 ISAPI 过滤器。该过滤器检查请求是否属于特殊类型,然后操作标头并继续处理请求。在调用另一个特殊 ISAPI 模块所需的操作方法中添加了两个标头。
所以我有 ISAPI C++ 代码,如下所示:

DWORD OnPreProc(HTTP_FILTER_CONTEXT *pfc, HTTP_FILTER_PREPROC_HEADERS *pHeaders)
{
    if (ManipulateHeaderInSomeWay(pfc, pHeaders))
    {
        return SF_STATUS_REQ_NEXT_NOTIFICATION;
    }
    return SF_STATUS_REQ_FINISHED;
}

我现在想重写此 ISAPI 过滤器作为 IIS7 的托管模块。所以我有这样的想法:

private void OnMapRequestHandler(HttpContext context)
{
    ManipulateHeaderInSomeWay(context);
}

现在怎么办?该请求似乎没有做它应该做的事情?
我已经编写了一个实现相同方法的 IIS7 本机模块。但这个方法有一个返回值,我可以用它来告诉下一步该做什么:

REQUEST_NOTIFICATION_STATUS CMyModule::OnMapRequestHandler(IN IHttpContext *pHttpContext, OUT IMapHandlerProvider *pProvider)
{
    if (DoSomething(pHttpContext))
    {
        return RQ_NOTIFICATION_CONTINUE;
    }
    return RQ_NOTIFICATION_FINISH_REQUEST;
}

那么有没有办法再次发送我的受控上下文?

I want to replace an old ISAPI filter that ran on IIS6. This filter checks if the request is of a special kind, then manipulates the header and continues with the request. Two headers are added in the manipulating method that I need for calling another special ISAPI module.

So I have ISAPI C++ code like:

DWORD OnPreProc(HTTP_FILTER_CONTEXT *pfc, HTTP_FILTER_PREPROC_HEADERS *pHeaders)
{
    if (ManipulateHeaderInSomeWay(pfc, pHeaders))
    {
        return SF_STATUS_REQ_NEXT_NOTIFICATION;
    }
    return SF_STATUS_REQ_FINISHED;
}

I now want to rewrite this ISAPI filter as a managed module for the IIS7. So I have something like this:

private void OnMapRequestHandler(HttpContext context)
{
    ManipulateHeaderInSomeWay(context);
}

And now what? The request seems not to do what it should?

I already wrote an IIS7 native module that implements the same method. But this method has a return value with which I can tell what to do next:

REQUEST_NOTIFICATION_STATUS CMyModule::OnMapRequestHandler(IN IHttpContext *pHttpContext, OUT IMapHandlerProvider *pProvider)
{
    if (DoSomething(pHttpContext))
    {
        return RQ_NOTIFICATION_CONTINUE;
    }
    return RQ_NOTIFICATION_FINISH_REQUEST;
}

So is there a way to send my manipulated context again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜爱皱眉﹌ 2024-09-01 09:18:14

我终于找到了。正如我在评论中所述,我向请求中添加了最终处理请求的 DLL 所需的两个标头。 url 标头包含 DLL 的路径。所以我必须重定向到该 DLL。

这是通过以下代码完成的:

private void OnMapRequestHandler(HttpContext context)
{
    ManipulateHeaderInSomeWay(context);
    string url = context.Request.Header["url"]; // path of the DLL

    // now this is the important call!
    context.Server.TransferRequest(url, true);
}

I finally found it. As I stated in the comments I add two headers to the request that are needed by my DLL that finally handles the request. The url header contains the path to the DLL. So I have to do a redirect to that DLL.

This is done with the following code:

private void OnMapRequestHandler(HttpContext context)
{
    ManipulateHeaderInSomeWay(context);
    string url = context.Request.Header["url"]; // path of the DLL

    // now this is the important call!
    context.Server.TransferRequest(url, true);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文