IIS7应用程序请求路由(arr反向代理)与托管模块结合 - 超时 [英] IIS7 Application Request Routing (arr reverse proxy) combined with managed module - time out

查看:678
本文介绍了IIS7应用程序请求路由(arr反向代理)与托管模块结合 - 超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个代理服务器来处理对内部站点的请求(隐藏原点)但同时检查数据包并异步后处理它们。

I am trying to build a proxy that would serve requests to an internal site (hiding the origin) but at the same time inspect the packets and asynchronously post-process them.

例如假设所有对 http://www.foo.com 的SOAP调用都将转到 http://192.168.1.1 ,同时存储在数据库中进行后期分析。内部服务器是一个黑盒子,因此更改它的内容超出了这个问题的范围。

E.g. let's say all SOAP calls to http://www.foo.com will go to http://192.168.1.1, and at the same time be stored in a DB for post analysis. The internal server is a black box, so changing something on it is out of this question scope.

无论如何,我已经配置了ARR,使用反向代理,进行了URL重写过滤有了通配符,所有作品都完美无瑕。然后,我尝试添加一个用C#编写的托管HttpModule,并挂钩到Application_BeginRequest和Application_EndRequest。我能够在最终请求(应用程序池处于集成模式)中访问请求标头,响应标头,甚至能够通过在Response.Filter上设置过滤器来读取输出流中的响应内容,该过滤器将所有写入缓存在附加内存流中。

Anyway, I have configured ARR, with reverse proxy, made URL rewrite filter with wildcards, all works flawless. Then, I tried to add an managed HttpModule written in C#, and hooked to Application_BeginRequest and Application_EndRequest. I am able to access request headers, response headers on end request (app pool being in integrated mode) and even able to read response content from the outputstream by setting a filter on Response.Filter, that caches all writes in an additional memory stream.

问题是,当我尝试读取(在模块BeginRequest处理程序内)来自请求的输入流时,ARR会停留一段时间并抛出一个

The problem is that the moment I try to read (inside the module BeginRequest handler) the input stream from the request, ARR stays a while and throws a


HTTP错误502.3 - 错误网关
操作超时处理程序
ApplicationRequestRoutingHandler
错误代码0x80072ee2

HTTP Error 502.3 - Bad Gateway The operation timed out Handler ApplicationRequestRoutingHandler Error Code 0x80072ee2

所以它超时。

查看失败的请求跟踪我看到:

Looking with Failed Request Tracing I see:


MODULE_SET_RESPONSE_ERROR_STATUS
警告
ModuleName =ApplicationRequestRouting,
Notification =EXECUTE_REQUEST_HANDLER,
HttpStatus = 502,HttpReason =Bad
Gateway,HttpSubStatus =3,
ErrorCode = 2147954402,
ConfigExceptionInfo =
SET_RESPONSE_ERROR_DESCRIPTION警告
ErrorDescription =操作时间
out

MODULE_SET_RESPONSE_ERROR_STATUS Warning ModuleName="ApplicationRequestRouting", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="502", HttpReason="Bad Gateway", HttpSubStatus="3", ErrorCode="2147954402", ConfigExceptionInfo="" SET_RESPONSE_ERROR_DESCRIPTION Warning ErrorDescription="The operation timed out"

现在网上的任何类似帖子都没有帮助,因为这不是超时错误(代理设置为120秒,页面答案不到100毫秒),以及我评论处理程序代码的那一刻尝试读取FORM数据或InputStream数据,一切都作为魅力。

Now any similar posts on the net didn't helped as this isn't a timeout error (proxy has 120 seconds setting, page answers in under 100 ms), and the moment I comment the code of the handler that tries to read FORM data or InputStream data, everything works as a charm.

即使我在读取后将输入流的位置设置为0,我仍然会有超时。
如果我在EndRequest上读取输入流,它会得到0个字节,即使它是一个POST请求。 (这显然是错误的)

Even if I set the position of the inputstream to 0 after reading it, I still get timeouts. If I read the input stream on EndRequest, it gets 0 bytes, even if it was a POST request. (which is clearly wrong)

ARR是否有一个错误,我尝试在尝试重新路由之前尝试读取输入流?

Does ARR has a bug in the fact that I try to read an input stream before it tries to re-route it?


使用的东西:Windows Server 2008 R2
IIS 7.5 ARR v2 .Net Framework 3.5
模块

Things used: Windows Server 2008 R2 IIS 7.5 ARR v2 .Net Framework 3.5 module

想法?
谢谢
/ Cosmin

Ideas? Thanks /Cosmin

推荐答案

如果你可以切换到.Net Framework 4,有一个解决方案为此。

If you can switch to .Net Framework 4, there is a solution for this.

在HttpModule事件处理程序中完成BeginRequest / EndRequest之后,添加对 HttpRequest.InsertEntityBody 的调用。

After you are done with your BeginRequest/EndRequest in your HttpModule event handler, add a call to HttpRequest.InsertEntityBody.

    /* BeginRequest event: Executes before request is processed */
    private void Application_BeginRequest(Object source, EventArgs e)
    {
        HttpApplication application = (HttpApplication)source;
        HttpRequest request = application.Context.Request;

        // Do something with request
        DoMyOwnRequestProcessing(request);

        // After you finish, make sure IIS gets the entity body
        // For example, Application Request Routing needs this
        request.InsertEntityBody();
    }

在MSDN上看一下这个: HttpRequest.InsertEntityBody

Take a look at this on MSDN: HttpRequest.InsertEntityBody.

这篇关于IIS7应用程序请求路由(arr反向代理)与托管模块结合 - 超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆