title: sending messages to single clients NOT identified by name (Identity)
body: <p>I know similar questions have been asked before, but here goes</p>
  
  <p>I have an ASP.NET app that serves images to connected clients. All clients are connected via owin with username and password and there could multiple clients connected with the same username and password.  However, each client may need to be served with unique images. This means that I need to use a unique "hub ID" to serve each image.</p>
  
  <p>The problem comes from retrieving this "hub ID" on the GetUserID method of the CustomUserProvider class. The IRequest parameter doesn't provide me with enough information to uniquely identify the connection. If I can get (which I can't (??)) to the Session state of the page then problem solved.</p>
  
  <p>Has anyone got any ideas. I'm thinking of perhaps using the url - which I can make unique for each connection....</p>
  
  <p>(Does anyone know how to get the original url of the page in the GetUserID)</p>
  
  <p>I solved this as follows. I append a unique id on the URL. Then in the GetUserID of the CustomUserProvider</p>
  
  <pre><code>  public string GetUserId(IRequest request)
      {
          string id = "";
          try
          {
              HttpContextBase  requestContext = request.Environment[typeof(HttpContextBase).FullName] as HttpContextBase;
  
              string url = requestContext.Request.UrlReferrer.AbsoluteUri;
              var parsedQuery = HttpUtility.ParseQueryString(url);
              id = parsedQuery["HUBID"];
  
          }
          catch { }
  
          return id;
  </code></pre>
  
  <p>This HUBID is the one referenced in the code behind:</p>
  
  <pre><code>   var hubContext = GlobalHost.ConnectionManager.GetHubContext&lt;Hubs.MimicHub&gt;();
          hubContext.Clients.User(HubID).addImage(MimicImage,
          ImageWidth, ImageHeight
          );
  </code></pre>