【发布时间】:2016-03-01 03:49:15
【问题描述】:
问题
我需要确定 SignalR 是否正在处理当前请求。
问题
如何获取SignalR 端点列表以检查端点是否存在
或
一种检查连接是否由SignalR 中间件提供服务的方法
上下文
我正在使用AspNet 5 SignalR 和JwtBearerAuthentication (Microsoft.AspNet.Authentication.JwtBearer)。
为了在所有平台上可靠地使用令牌验证 SignalR 连接,我必须使用查询字符串来传递它。
用例
我需要的实际代码可以在here找到:
app.UseJwtBearerAuthentication(options => {
options.Events = new JwtBearerEvents {
// Note: for SignalR connections, the default Authorization header does not work,
// because the WebSockets JS API doesn't allow setting custom parameters.
// To work around this limitation, the access token is retrieved from the query string.
OnReceivingToken = context => {
// Note: when the token is missing from the query string,
// context.Token is null and the JWT bearer middleware will
// automatically try to retrieve it from the Authorization header.
// >>> Here i need to check if the connection is served by signalr
// >>> And if not, simply not take token from query string
context.Token = context.Request.Query["access_token"];
return Task.FromResult(0);
}
};
});
【问题讨论】:
-
编写自定义中间件来检测查询字符串中是否存在令牌?
-
如果您查看“我需要这个的实际代码”,它已经表现为某种中间件。差别不大。如果您知道一种确定连接是否由 SignalR 在中间件中提供服务的方法,我相信我可以在需要的地方使用相同的逻辑:)
-
什么是“我需要的实际代码”?发布这可能会增加您获得答案的机会。
-
我修复了链接(已更改和 404'ed)并添加了代码摘录。如果仍然不清楚我为什么需要它,请问:)
-
@DovydasNavickas 你是怎么解决这个问题的?
标签: c# asp.net signalr asp.net-core jwt