signalR generating different ID for various instances

邮差的信 提交于 2019-12-06 04:11:43

问题


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.



来源:https://stackoverflow.com/questions/25685855/signalr-generating-different-id-for-various-instances

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!