【发布时间】:2020-05-10 14:00:46
【问题描述】:
.net 核心 2.1
中心代码:
[Authorize]
public class OnlineHub : Hub
{
public override async System.Threading.Tasks.Task OnConnectedAsync()
{
int userId = Context.UserIdentifier;
await base.OnConnectedAsync();
}
[AllowAnonymous]
public override async System.Threading.Tasks.Task OnDisconnectedAsync(Exception exception)
{
var b = Context.ConnectionId;
await base.OnDisconnectedAsync(exception);
}
客户端代码:
$(document).ready(() => {
let token = "token";
const connection = new signalR.HubConnectionBuilder()
.withUrl("https://localhost:44343/online", { accessTokenFactory: () => token })
.configureLogging(signalR.LogLevel.Debug)
.build();
connection.start().catch(err => console.error(err.toString()));
});
没有 [Authorize] 一切正常,除了 OnConnectedAsync 中的 Context.UserIdentifier,它是可以解释的,但是......在 Hub 类上使用 [Authorize] 属性,OnConnectedAsync 开始工作并且 OnDisconnected 根本不会触发,包括 30 秒超时(通过默认)。
有什么想法吗?
【问题讨论】:
-
OnConnectedAsync start working and OnDisconnected not fires at all浏览器控制台标签有错误吗? -
关于用户关闭浏览器(或标签页)事件的案例
-
你是如何解决这个问题的?问题是什么?
标签: asp.net-core signalr asp.net-core-signalr