【发布时间】:2025-12-27 10:55:06
【问题描述】:
这里我们使用的是 asp.net core singnalR alpha2 版本。如何为组(用户组)发送通知?如果有任何场景示例,请在此处发布示例链接。
在 Hub 中使用组写入方法。
public class SignalRCommonHub : Hub
{
public void SendToGroup(int groupId, int userId)
{
Clients.Group(groupId.ToString()).InvokeAsync("refresh", groupId, userId);
}
}
在控制器中调用 hub 方法。
private readonly IHubContext<SignalRCommonHub> isignalRhub;
public SignalRModel(IHubContext<SignalRCommonHub> signalRhub)
{
this.isignalRhub = signalRhub;
}
public void RefreshPage(int groupId, int userId)
{
this.isignalRhub.Clients.Group(groupId.ToString()).InvokeAsync("refresh", groupId, userId);
}
在客户端调用方法时不会触发。
使用可用signalR示例基于组(用户组)的用户在线状态更新意味着在此处发布链接。提出如何实现用户在线状态的想法。
谢谢,
【问题讨论】:
-
请添加一些关于您尝试过的内容、您正在使用的代码的基础知识以及您打算如何指定组的信息。
-
请花一些时间来清理您的问题并格式化代码。
标签: c# asp.net-core signalr