SignalR: How to send data to IConnected.Connect()

后端 未结 1 1264
时光取名叫无心
时光取名叫无心 2020-12-25 13:44

I implement the Connect() method on IConnected interface to add new connections to the correct groups. This works well except for one thing: in ord

相关标签:
1条回答
  • 2020-12-25 14:03

    I solved this by adding my information to the querystring, which is available on the IConnected.Connect() method.

    On the .NET client you pass the querystring into your HubConnection:

    var connection = new HubConnection("http://localhost:8080/", "myInfo=12345");
    

    On the JS client, you set the qs property before starting the connection:

    $.connection.hub.qs = "myInfo=12345";
    

    You can then access this information on the server in the Connect() method:

    var myInfo = Context.QueryString["myInfo"];
    Groups.Add(Context.ConnectionId, myInfo);
    
    0 讨论(0)
提交回复
热议问题