简体   繁体   English

如何将 SignalR 与多页 web 应用程序一起使用?

[英]How to use SignalR with multi page web app?

The SignalR user session ends after changing the page. SignalR 用户 session 换页后结束。 A new session opens on the new page.新的 session 在新页面上打开。

I need a connection that will continue as long as I log out of Hub.我需要一个连接,只要我退出 Hub 就会继续。

As far as I know, when you connect the signalR hub server, it will generate a connectionID.据我所知,当你连接signalR集线器服务器时,它会生成一个connectionID。

Each new session will use specific connectionid, we couldn't modify the conenctionid when you used the new session.每个新的 session 都会使用特定的连接 ID,当您使用新的 session 时,我们无法修改连接 ID。

If you want to let all the tab connect as one user account, you could try to check the username when the connection started and then store the username and connectionid as one to more in the server memory or else.如果您想让所有选项卡作为一个用户帐户连接,您可以尝试在连接开始时检查用户名,然后将用户名和 connectionid 作为一对多存储在服务器 memory 或其他中。

Then if other user send message to this user, you could get the connectionid according to the username and use Clients.Client(conid).SendAsync method to send the request.然后如果其他用户向该用户发送消息,您可以根据用户名获取 connectionid 并使用Clients.Client(conid).SendAsync方法发送请求。

More details about how to achieve it, you could refer to this reply .更多详细的实现方法,可以参考这个回复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM