Nếu người dùng làm mới trang, được coi là kết nối mới. Bạn đúng là ngắt kết nối dựa trên thời gian chờ.
Bạn có thể xử lý các sự kiện Kết nối/Kết nối lại và Ngắt kết nối trong Trung tâm bằng cách triển khai
SignalR.Hubs.IConnected
và
SignalR.Hubs.IDisconnect
.
Ở trên được gọi là SignalR 0.5.x.
Từ the official documentation (hiện cho v1.1.3):
public class ContosoChatHub : Hub
{
public override Task OnConnected()
{
// Add your own code here.
// For example: in a chat application, record the association between
// the current connection ID and user name, and mark the user as online.
// After the code in this method completes, the client is informed that
// the connection is established; for example, in a JavaScript client,
// the start().done callback is executed.
return base.OnConnected();
}
public override Task OnDisconnected()
{
// Add your own code here.
// For example: in a chat application, mark the user as offline,
// delete the association between the current connection id and user name.
return base.OnDisconnected();
}
public override Task OnReconnected()
{
// Add your own code here.
// For example: in a chat application, you might have marked the
// user as offline after a period of inactivity; in that case
// mark the user as online again.
return base.OnReconnected();
}
}