在集线器上下文之外的SignalR集线器中调用Caller方法 [英] calling the Caller method in SignalR hub outside the hub context

查看:108
本文介绍了在集线器上下文之外的SignalR集线器中调用Caller方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SignalR的Caller方法有个疑问.在hub方法中,我们可以像这样调用客户端函数.

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..

推荐答案

在集线器之外,显然没有呼叫者,因为服务器是发起者.

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();

那将是唯一的.

这篇关于在集线器上下文之外的SignalR集线器中调用Caller方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆