Can I transfer an HTTP connection from IIS / ASP.NET to another application or service?

I am developing an ASP.NET MVC application that provides (other than regular HTML pages) JSON and XML REST services, as well as Web Sockets .

In an ideal world, I could use the same URLs for the web socket interface as for other services (and determine what data will be returned at the request of the user agent), but knowing that IIS wasn’t built for persistent connections, I need to know if there is a way that I can accept (and possibly even shake hands) a connection to web sockets, and then transfer the connection to another service running on the server.

I have a workaround if this is not possible , which is mainly due to using ASP.NET to check the update headers of the web socket connections and the HTTP/1.1 302 Found response, which points to another host that has the web socket service configured to listen directly to appopriate endpoints.

+4
source share
4 answers

If I fully understand your goal, I believe that you can use the IIS7 / 7.5 application request routing module to accomplish this.

Here is a short link: http://learn.iis.net/page.aspx/489/using-the-application-request-routing-module/

+1
source

Instead of 302 responses, you can use ISAPI_rewrite to directly access the corresponding endpoint (and manipulate the HTTP header to get it there)

http://www.isapirewrite.com/docs/

Otherwise, IIS will not be able to disconnect the HTTP connection. The current MSFT method is to use 302 or something else that intercepts a raw socket and performs header processing before being sent to IIS (or any other application).

+1
source

It seems to me that it would be better to ask Microsoft than to ask us. Web Sockets is a new technology, and instead of searching for a hack, you can ask Microsoft how they plan to support it. IIS is their software. Pull out on http://iis.net (possibly at http://forums.iis.net ) and see what you find out.

0
source

The way to do this is to use the unique session identifier associated with the Http session. From the description it seems that you might need to combine this into one instance of HttpApplication, but this is optional (you can also continue the session in many instances of the application). In any case, this session identifier must be bound in some way to each Http request (either using a cookie, querystring, a static variable with an HttpApplication instance, form data). Then you save the Http session credentials somewhere with an identifier.

This identifying information may vary depending on your needs, but may entail an entire HTTP request or just some truncated view that serves your specific purpose.

Using this SessionID somewhere in the Http request allows you to recover any information needed to call and interact with the corresponding services. Service instances can also be session bound.

Basically, I suggest that you NOT directly pass the Http connection to the external process, but instead pass the necessary data to the external process and allow you to create a mechanism for sending callback data. I think that studying the mediator template can help you understand that I I mean here. http://en.wikipedia.org/wiki/Mediator_pattern . Hope this helps.

0
source

Source: https://habr.com/ru/post/1332827/


All Articles