Javascript 信号器-更新特定用户(推送通知)

Javascript 信号器-更新特定用户(推送通知),javascript,node.js,asp.net-core,signalr,asp.net-core-signalr,Javascript,Node.js,Asp.net Core,Signalr,Asp.net Core Signalr,我很难只更新一个特定的用户 我正在开发一些asp.net核心web应用程序,我想为我的项目实现推送通知。我将进一步解释一下我在应用程序中所做的工作 我有一个页面,用户可以在那里发布一些东西(比如在facebook上)。在那个帖子上,每个人都可以喜欢/不喜欢它(喜欢按钮)或评论它(也可以删除评论)。在这方面,我对signar的实现与wait Clients.All.SendAsync(“UpdateComments”,userId,postId)配合得很好 现在我想向发布帖子的用户发送通知。 我试

我很难只更新一个特定的用户

我正在开发一些asp.net核心web应用程序,我想为我的项目实现推送通知。我将进一步解释一下我在应用程序中所做的工作

我有一个页面,用户可以在那里发布一些东西(比如在facebook上)。在那个帖子上,每个人都可以喜欢/不喜欢它(喜欢按钮)或评论它(也可以删除评论)。在这方面,我对signar的实现与
wait Clients.All.SendAsync(“UpdateComments”,userId,postId)配合得很好

现在我想向发布帖子的用户发送通知。 我试着这样做
等待Clients.User(userId).sendaync(“SendNotification”,notificationText)但不工作。当我调试它时,在这部分
User(someId)
中,它希望我发送
connectionId
,而我没有为我想要更新的用户发送。我只有调用当前连接的用户的connectionId

我的问题是:如何使用我的表中的userId更新用户,或者如何根据我的userId获取connectionId如果我无法实现这一点,是否有一种方法可以自动将用户(当他登录到应用程序时)添加到某个信号器组连接中,而不需要用户自己激活连接

我在谷歌上搜索了很多,但没有找到答案。
是我在我的应用程序中实现signalR所遵循的链接。

我已经在写一篇小博文了

您需要编写一个方法发送给特定的用户id,如下所示

  public async Task Send(string userId)
    {
        var message = $"Send message to you with user id {userId}";
        await Clients.Client(userId).SendAsync("ReceiveMessage", message);
    }
然后听听这件事

(function () {
        var connection = new signalR.HubConnectionBuilder().withUrl("/connectionHub").build();

        connection.start().then(function () {
            console.log("connected");

            connection.invoke('getConnectionId')
                .then(function (connectionId) {
                    sessionStorage.setItem('conectionId', connectionId);
                    // Send the connectionId to controller
                }).catch(err => console.error(err.toString()));;


        });

        $("#sendmessage").click(function () {
            var connectionId = sessionStorage.getItem('conectionId');
            connection.invoke("Send", connectionId);
        });

        connection.on("ReceiveMessage", function (message) {
            console.log(message);
        });

    })();

我已经在写小博客了

您需要编写一个方法发送给特定的用户id,如下所示

  public async Task Send(string userId)
    {
        var message = $"Send message to you with user id {userId}";
        await Clients.Client(userId).SendAsync("ReceiveMessage", message);
    }
然后听听这件事

(function () {
        var connection = new signalR.HubConnectionBuilder().withUrl("/connectionHub").build();

        connection.start().then(function () {
            console.log("connected");

            connection.invoke('getConnectionId')
                .then(function (connectionId) {
                    sessionStorage.setItem('conectionId', connectionId);
                    // Send the connectionId to controller
                }).catch(err => console.error(err.toString()));;


        });

        $("#sendmessage").click(function () {
            var connectionId = sessionStorage.getItem('conectionId');
            connection.invoke("Send", connectionId);
        });

        connection.on("ReceiveMessage", function (message) {
            console.log(message);
        });

    })();

这个回答回答了你的问题吗?这个回答回答了你的问题吗?