title: Use static dictionary in asp.net web application
body: <p>I use SignalR in my asp.net web application. Session state doesn't exist in SignalR hub, so I decided to save <code>username &lt;-&gt; connectionId</code> pair in static dictionary.</p>
  
  <pre><code>public static class UsernameConnectionsMaps
  {
      private static Dictionary&lt;string, string&gt; data = new Dictionary&lt;string, string&gt;();
  
      public static void Add(string username, string connectionId)
      {
         data[username] = connectionId;
      } 
  
      public static string Get(string username)
      {
         return data[username];
      }
  
      public static void Remove(string username)
      {
         return data.Remove(username);
      }  
  }
  </code></pre>
  
  <p>On a particular controller request, I want to send data to the client with signalR. Knowing the username of current user, I can easily get connectionId for the client and send data.</p>
  
  <p>I use <code>Get</code> method in my controller.
  I use <code>Add</code> and <code>Remove</code> methods in hub's <code>OnConnected()</code> and <code>OnDisconnected()</code> methods respectively.</p>
  
  <p>I am interested in, if this solution will have any problem regarding thread safety (or other) in my web application? What will be better approach?</p>