【发布时间】:2019-07-22 13:59:41
【问题描述】:
我正在使用 JWT 令牌对用户进行身份验证。它工作正常,Context.User 被正确填充。问题是它只有一个用户,集线器不是每个连接都有一个用户吗?
在OnNotification 方法中,我想循环浏览所有当前连接,验证用户是否有权查看我要发送的内容,然后如果他/她有权限则发送,否则就发送。
我怎样才能做到这一点?
[Authorize]
public class NotifyHub : Hub {
private readonly MyApi _api;
public NotifyHub(MyApi api) {
_api = api;
_api.Notification += OnNotification;
}
private async void OnNotification(object sender, Notification notification) {
// can access Context.User here
await Clients.All.SendAsync("Notification", notification);
}
}
【问题讨论】:
-
解决方法Here 的示例。但你会改用
Context.User。
标签: c# authentication asp.net-core signalr asp.net-core-signalr