SignalR Maintain browser connection ID

I am developing a chat application using signalr and asp.net mvc 4. If the user is added for the first time, he will assign a connection identifier and he will chat with other clients, but if he refreshes his page, he will assign a new connection identifier.

My question is how to maintain user connection id when updating browser?

Any help would be appreciated.

+4
source share
3 answers

If the user is added for the first time, he will assign a connection identifier that will be stored in the session or some specific static variable if the page refreshes this time check. The sessive variable is empty or not if the current identifier is not passed

if(Session["id"] != null )
{
   -- use last added id
}

I think this may help you.

+1
source

I would add persistence through the database or cache.

In my decision, I added the presidency through the database, for each session I assigned a unique identifier that was treated as a signalR group, and in each browser update the client registered with this unique identifier, and I would assign a new connection id to the same unique identifier, which is the name of the group. and sending the message to the client is done through groups.

_signalrDispatcher.Clients.Groups("group name").SendData(data);
0
source

, connectionIds. , .

OnConnected OnReconnected connectionId ( , ), connectionId ( ).

OnDisconnected / . , , . , , .

. , , . , ( , redis).

, .

0
source

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


All Articles