如何在 C# 中操作标头然后继续处理它?
我想替换在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于找到了。正如我在评论中所述,我向请求中添加了最终处理请求的 DLL 所需的两个标头。
url
标头包含 DLL 的路径。所以我必须重定向到该 DLL。这是通过以下代码完成的:
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: