Asp.net mvc SignalR—如何访问其他服务器端类中的用户映射以向特定用户发送通知

Asp.net mvc SignalR—如何访问其他服务器端类中的用户映射以向特定用户发送通知,asp.net-mvc,signalr,signalr-hub,Asp.net Mvc,Signalr,Signalr Hub,我已经在我的MVC项目中实现了内存中的存储映射,以存储userId及其相关的connectionsId,如下面的映射链接所示。问题是我无法访问另一个服务器端类中的映射实例并向特定用户发送通知。我应该如何修改Hub或SendNotification类以发送通知。请告诉我怎么做 \\ here is the sample hub class with onconnected and disconnted same as in mapping link public class Notificatio

我已经在我的MVC项目中实现了内存中的存储映射,以存储userId及其相关的connectionsId,如下面的映射链接所示。问题是我无法访问另一个服务器端类中的映射实例并向特定用户发送通知。我应该如何修改Hub或SendNotification类以发送通知。请告诉我怎么做

\\ here is the sample hub class with onconnected and disconnted same as in mapping link
public class NotificationHub : Hub
{
    private readonly static ConnectionMapping<string> _connections =  new ConnectionMapping<string>();

    public void SendChatMessage(string who, string message)
    {
        string name = Context.User.Identity.Name;

        foreach (var connectionId in _connections.GetConnections(who))
        {
            Clients.Client(connectionId).addChatMessage(name + ": " + message);
        }
    }
}

\\ other server class where to call hub
public class SendNotification
{
    Public void SaveToDb(string userName, class entity)
    {
        // save to database call
        // send Notification to User userName through SignalR if user Exists in Mapping
    }
}
这是一个信号映射链接


下面是如何访问外部中心

您看过背板文档了吗?看

我们有一个多实例web层,其中包含许多Signal客户端。web层中的任何实例都可以与任何浏览器客户端通信。集线器中的代码不会更改。启动时只有额外的逻辑-请参阅上面的文档