javascript - 在页面刷新时重新连接 SignalR 客户端?

标签 javascript c# .net signalr

在我的场景中,我使用 SignalR 进行登录。

如果用户一使用用户名“abc”登录,用户二使用用户名“abc”登录,则用户一将被踢出并重定向两个登录页面。

但是,如果用户一已登录并刷新页面,然后用户二尝试登录用户一将不会被踢。因为在刷新用户时,其中一个失去了连接。我尝试了很多解决方案,例如尝试在断开连接事件时重新连接,但它不起作用。

有人可以帮忙吗?

最佳答案

客户端断开连接场景

In a browser client, the SignalR client code that maintains a SignalR connection runs in the JavaScript context of a web page

When the user closes a browser window or tab, or navigates to a new page or refreshes the page, the SignalR connection immediately ends because SignalR client code handles that browser event for you and calls the Stop method. In these scenarios, or in any client platform when your application calls the Stop method, the OnDisconnected event handler executes immediately on the server and the client raises the Closed event (the event is named disconnected in JavaScript)

Disconnection Scenarios(Client & Server)

关于javascript - 在页面刷新时重新连接 SignalR 客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47981403/

相关文章:

javascript - 在本地主机上进行开发时,Firebase 分析是否有效?

javascript - 如何在 div 中添加标签

javascript - AngularJS/JQuery - 没有关联标签的表单输入

c# - 如何为游戏编译 C# 脚本

.net - Visual Studio 2010 从 2005 年开始?

javascript - 下一个上一个图标在 Owl Carousel 2 中不起作用

c# - DataType 来存储和使用具有特定限制的通用类型?

c# - 如何在带有 SSL 的 C# 中使用 HTTP GET 请求? (违反协议(protocol))

c# - 将数据存储在库中是不好的做法吗?

C# 格式化约定