No access to the Session information through SignalR Hub. Is my design is wrong?

前端 未结 4 1151
南方客
南方客 2020-11-29 07:21

I\'ve just discovered you can\'t access the current session within the SignalR Hub.

Simplified my scenario: I\'ve tried to write a chat.

The name of the curr

4条回答
  •  再見小時候
    2020-11-29 08:12

    You could send values from client to server hub via Query String.

    Before the $.connection.hub.start() method you could add something like this:

    Client JS Code:

    // Replace "some value" with the session value or anything you want
    $.connection.hub.qs = { "Name": "some value" };
    
    $.connection.hub.start()...bla bla bla
    

    On the server side on the Hub you could use this in any method:

    string ClientValue= Context.QueryString["Name"].ToString();
    

    I did not test with sessions, but of course on client side you could be as awesome as you can.

提交回复
热议问题