title: SignalR Hub OnDisconnectedAsync Method Does Not Get Hit in Blazor Server
body: <p>Here I am trying to remove <code>ConnectionId</code> from connected connectedId list <code>UserHandler.ConnectedUser</code> in <code>OnDisconnectedAsync</code> method of my hub.<br>
  But the problem is that when ever user gets logout from application or close that window the <code>OnDisconnectedAsync</code> method on hub does not get hit.<br />
  <br><br>Any help with my code will be grate. Thank you.
  <br><br>
  Below is my hub</p>
  <pre><code>public class ChatHub : Hub
  {
      public List&lt;string&gt; SendingUserList = new List&lt;string&gt;();
      public async Task SendMessage(string to, string message)
      {
          var senderConnectionId = Context.ConnectionId;
          SendingUserList.Add(to);
          SendingUserList.Add(senderConnectionId);
          foreach (var connectionId in SendingUserList)
          {
              await Clients.Client(connectionId).SendAsync(&quot;ReceiveMessage&quot;, message);
          }
      }
      public override Task OnConnectedAsync()
      {
          Clients.All.SendAsync(&quot;ReciveUser&quot;, UserHandler.UserName, Context.ConnectionId);
          return base.OnConnectedAsync();
      }
      public override async Task OnDisconnectedAsync(Exception e)
      {
          UserHandler.ConnectedUser.Remove(Context.ConnectionId));
          await base.OnDisconnectedAsync(e);
      }      
  }
  public static class UserHandler
  {
      public static HashSet&lt;string&gt; ConnectedUser = new HashSet&lt;string&gt;();
      public static string UserName { get; set; }
  }
  </code></pre>
  <p><br><br>Below is my remaining code</p>
  <pre><code>    protected override async Task OnInitializedAsync()
      {
          UserHandler.UserName = httpContextAccessor.HttpContext.User.Identity.Name;
          hubConnection = new HubConnectionBuilder()
              .WithUrl(NavigationManager.ToAbsoluteUri(&quot;/chathub&quot;))
              .Build();
          hubConnection.ServerTimeout = TimeSpan.FromMinutes(60);
          hubConnection.On&lt;string&gt;(&quot;ReceiveMessage&quot;, BroadcastMessage);
          hubConnection.On&lt;string,string&gt;(&quot;ReciveUser&quot;, RefreshUserList);
  
          await hubConnection.StartAsync();
  
          StateHasChanged();
      }
      private void RefreshUserList(string connectedUserId, string connectionId )
      {
          UserHandler.ConnectedUser.Add(connectionId);
          connectedUserList = UserHandler.ConnectedUser;
          StateHasChanged();
      }
      private void BroadcastMessage(string message)
      {
          var encodedMsg = $&quot;{message}&quot;;
          messages.Add(encodedMsg);
          StateHasChanged();
      }
      public async ValueTask DisposeAsync()
      {
          await hubConnection.DisposeAsync();
      }
  </code></pre>