calling the Caller method in SignalR hub outside the hub context

故事扮演 提交于 2019-12-07 05:36:15

问题


I have a question in my mind about the Caller method of SignalR. In the hub method we can call a client side function like this.

Clients.Caller.addContosoChatMessageToPage(name, message);

but when i use to call it from outside the hub context it is 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 other way to implement it.. by now i use to implement this

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

but now we are not claim based authentication so it will be a problem if the same usernm are logged..


回答1:


Outside of the hub, there obviously is no caller because the server is the one who initiates.

If you are worried about unique user names, you'll need to implement a custom IUserIdProvider, or you need to manage connection ids per user in some other way. Then you could call

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

which would be unique.



来源:https://stackoverflow.com/questions/28468294/calling-the-caller-method-in-signalr-hub-outside-the-hub-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!