无法使用asp.net MVC SignalR向特定用户发送SqlDependency推送通知

时间:2016-12-07 14:11:44

标签: asp.net-mvc signalr signalr-hub signalr.client

我有一个带有静态方法的集线器,该方法当前向所有用户广播通知。

public class NotificationHub : Hub
{
    [HubMethodName("sendNotifications")]
    public static void SendNotifications(string userId)
    {

        string connectionid = ConnectedUsers.FirstOrDefault(a => a.UserName == userId).ConnectionId;
        context.Clients.All.notify("added"); 
    }
}

它正在工作,但是当我向特定用户广播消息时

[HubMethodName("sendNotifications")]
    public static void SendNotifications(string userId)
    {

        string connectionid = ConnectedUsers.FirstOrDefault(a => a.UserName == userId).ConnectionId;
        context.Clients.Client(connectionid).notify("added"); 
    }

它不起作用。我正在从Follow Method调用SendNotification。

void sqlDep_OnChange(object sender, SqlNotificationEventArgs e, string EmpID)
    {
        if (e.Type == SqlNotificationType.Change)
        {
            NotificationHub.SendNotifications(EmpID);
            RegisterNotification(DateTime.Now, EmpID);
        }
    }

先谢谢。

0 个答案:

没有答案
相关问题