Is it possible to change querystring on a SignalR connection without perform a stop and start?
I´m doing this:
$.connection.hub['qs'] = {arg1: 'kkkk', arg2: 'xxx',...};
$.connection.hub.stop();
$.connection.hub.start();
This stop/start is causing my system to interpret it is as a connection break up, what is undesirable for many reasons.
When I remove it, methods are invoked with older querystring arguments.
The code you have to update the query string ($.connection.hub.qs = {arg1: 'kkkk', arg2: 'xxx',...};
) will be reflected in the query string of any future requests SignalR makes for that connection.
In the case of anything but the WebSocket transport, i.e. server-sent events, forever frame, and long polling, any subsequent server hub invocation should be made by an Ajax request with the updated querystring.
However, if WebSockets is in use, there shouldn't ever be a subsequent request to attach the updated query string to. At least this is the case if the connection doesn't die forcing a reconnect.
One solution is to restart the connection like you did. It would be better yet if you would set the query string before you start the connection in the first place.
If you really need to change the query string after the connection starts and you don't want the system to interpret this as a brand new connection, you might be able to do something like the following:
$.connection.hub.qs = {arg1: 'kkkk', arg2: 'xxx',...};
$.connection.hub.transport.lostConnection($.connection.hub);
This will basically trick the transport into thinking the connection is dead and cause it to reconnect with the updated query string without renegotiating and connecting with a new ConnectionId
. The problem with this approach is that the second line uses an undocumented API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With