Signalr IConnectionIdGenerator not found in SignalR 1.0rc2 release

耗尽温柔 提交于 2019-12-06 11:28:32

This is gone indeed and there is no direct replacement as you're supposed to do the user/connection mapping manually now.

I solved it using a HubPipelineModule and setting up a group for all connections of that user.

public class AuthenticationHubPipelineModule : HubPipelineModule
{
    protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
    {
        var id = MyUserManager.Instance.CurrentUserID.ToString();

        context.Hub.Groups.Add(context.Hub.Context.ConnectionId, id);

        return base.OnBeforeIncoming(context);
    }
}

When you then want to reach out to the user, you can just send it to that group like this:

var context = GlobalHost.ConnectionManager.GetHubContext<YourHub>();
context.Clients.Group(userId).yourCallbackMethod();

Hope this helps, Yves

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