signalR generating different ID for various instan

2019-04-09 10:05发布

问题:

I have created web chat application using signalR. When user is logged in, user can open only 3-4 tabs and each time different connection ID is generated. I want that when we open new tab or refresh the page new connection id should not be generated. I want to use the existing connection id. For that I tried to implement the LocalStorage variable to store the hub connection. But Problem is i am unable to parse the value of localstorage variable.

Can Anyone give me the solution to my problem or can anyone give me any other solution to the problem?

I have already tried this http://kevgriffin.com/maintaining-signalr-connectionids-across-page-instances/ but it dosen't work for me

回答1:

If user is authenticated you can store different connectionIds in the HashSet. The key for the HashSet will be the user's name.

http://www.asp.net/signalr/overview/signalr-20/hubs-api/mapping-users-to-connections

You can use this method even if you are not authenticated. In this case you can use SessionId instead of username.

EDITED:

I have found another method. In this article Alex Ford advices to limit your connections to 3.