public override async Task OnDisconnectedAsync(Exception exception) { try { _visitor.LetOutVisitor(Context.ConnectionId); var user = _db.Connections.Where(c => Context.ConnectionId == c.ConnectionID && c.Connected) .OrderByDescending(c => c.ConnectionDate) .FirstOrDefault(); var host = _db.Connections.Where(c => c.User.UserName == _configuration["HostUser:Name"] && c.Connected) .OrderByDescending(c => c.ConnectionDate) .FirstOrDefault(); if (host != null && user != null) { _logger.LogDebug($"{host.User.UserName}({host.ConnectionID}) is already connected."); await Clients.Client(host.ConnectionID).SendAsync("iamout", user.User.UserName); _logger.LogDebug($"{user.User.UserName} is disconnected. Detail: {exception?.Message}"); } } catch (Exception ex) { _logger.LogError(ex, $"Unexpected error is occured {ex.Message}"); } finally { await base.OnDisconnectedAsync(exception); } }