Calling SignalR hub clients from elsewhere in system

后端 未结 5 1021
情书的邮戳
情书的邮戳 2020-12-07 12:06

I\'ve set up a SignalR hub to communicate between the server and client. The hub server side code is stored in a class called Hooking.cs. What I want is to be able to call a

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 12:46

    This is the correct way for SignalR 2.x:

    var context = GlobalHost.ConnectionManager.GetHubContext();
    context.Clients.All.addMessage(message);
    

    Basically, you can use the dependency resolver for the current host to resolve the IConnectionManager interface which allows you to get ahold of the context object for a hub.

    Further information can be found in the official documentation.

提交回复
热议问题