2013-02-06 43 views
2

我用来实现用下面的代码我自己的连接ID发生器:Signalr IConnectionIdGenerator在SignalR 1.0rc2发布找不到

public class MyConnectionFactory : IConnectionIdGenerator 
{ 
    public string GenerateConnectionId(IRequest request) 
    { 
     return MyUserManager.Instance.CurrentUserID.ToString(); 
    } 
} 

这是工作的罚款与SignalR 0.5.3版本,但更新到SignalR 1.0rc2后找不到名称空间或类名称。此外,我无法在这里找到关于此突变的任何注释https://github.com/SignalR/SignalR/blob/master/ReleaseNotes.md您能帮我解决这个问题吗?

回答

5

这确实没有了,因为您现在应该手动执行用户/连接映射,所以没有直接替换。

我使用HubPipelineModule解决了这个问题,并为该用户的所有连接设置了一个组。

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

当你那么想伸手去给用户,你可以将它发送给该组是这样的:

​​

希望这有助于 伊夫

+0

这是一个完美的解决方案,谢谢! –

+0

我有同样的问题,但我可以使用你的代码,你能解释你的意思吗“你应该现在手动进行用户/连接映射” – Jon

+1

对于读这个OnBeforeIncoming的人不会被调用,除非打电话给服务器是制造的。我相信当调用hub.start时,会调用GenerateConnectionId – Jon