在我的场景中,我使用 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)
关于javascript - 在页面刷新时重新连接 SignalR 客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47981403/