Calling Caller Method in SignalR Hub Out of Hub Context

I have a question about the Caller SignalR method. In the hub method, we can call the client side function as follows.

Clients.Caller.addContosoChatMessageToPage(name, message); 

but when I use it to call the hub context from outside, is it not found or not implemented? like this..

  var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>(); context.Clients.Caller.reportProgress(recordCount,totalCount); 

Can someone enlighten me in this part or is there another way to implement it. I am currently using to implement this

  var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>(); context.Clients.User(CurrentUser.Usernm).reportProgress(recordCount,totalCount); 

but now we are not claims-based authentication, so this will be a problem if the same usernm is registered.

+5
source share
1 answer

There is obviously no caller outside the hub, because the server is the initiator.

If you are concerned about unique usernames, you need to implement a custom IUserIdProvider , or you need to manage the connection identifiers for the user in another way. Then you can call

 context.Clients.Client(connectionId).reportProgress(); 

which would be unique.

+5
source

Source: https://habr.com/ru/post/1213192/


All Articles