public override Task OnConnected() { Debug.WriteLine("#{0} - Event: {1}, Method: {2}", DateTime.Now.ToString("hh:mm:ss.fff"), "-", "NotificationHub.OnConnected"); var currentUser = _userService.GetUserByUsername(Context.User.Identity.Name); if (!currentUser.IsRegistered()) { return(null); } var connectionId = Context.ConnectionId; var client = new Client() { ConnectionId = connectionId, User = currentUser }; if (_clients.Where(c => c.User == currentUser).Any()) { _clients.FirstOrDefault(c => c.User == currentUser).ConnectionId = connectionId; } else { _clients.Add(client); } lock (_syncRoot) { Clients.Client(connectionId).connected(currentUser.Username, "connected"); } _sessionService.AddNewSession(); return(base.OnConnected()); }