signalR为各种实例生成不同的ID [英] signalR generating different ID for various instances

查看:114
本文介绍了signalR为各种实例生成不同的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用signalR创建了Web聊天应用程序.当用户登录时,用户只能打开3-4个选项卡,并且每次生成不同的连接ID时.我希望当我们打开新标签页或刷新页面时,不应生成新的连接ID.我想使用现有的连接ID.为此,我尝试实现LocalStorage变量来存储集线器连接.但是问题是我无法解析localstorage变量的值.

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?

我已经尝试过 http://kevgriffin.com/maintaining-signalr-connectionids-across-page-instances/,但对我却不起作用

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

推荐答案

如果用户通过了身份验证,则可以在HashSet中存储不同的connectionId.HashSet的密钥将是用户名.

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

即使您未通过身份验证,也可以使用此方法.在这种情况下,您可以使用SessionId代替用户名.

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

已编辑:

我找到了另一种方法.在文章中,Alex Ford建议限制了您的联系到3.

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

这篇关于signalR为各种实例生成不同的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆