.Net Core 5.0 迁移的 SignalR 问题,app.UseSignalR -> app.UseEndpoints
SignalR Issue with .Net Core 5.0 migration, app.UseSignalR -> app.UseEndpoints
我已经从 Net Core 3.1 迁移到 5.0,但更新后我无法让 signalR 连接。每当它尝试连接到集线器时,我都会收到 401 错误。
错误日志
2020-12-17 15:47:07.351 -08:00 [INF] AuthenticationScheme: Identity.Application was challenged.
2020-12-17 15:47:07.351 -08:00 [INF] Request finished HTTP/2 POST
https://blah.blah.org:5001/range/negotiate?negotiateVersion=1 text/plain;charset=UTF-8 0 - 401 0
- 4.4068ms
2020-12-17 15:47:12.355 -08:00 [INF] Request starting HTTP/2 POST
https://blah.blah.org:5001/range/negotiate?negotiateVersion=1 text/plain;charset=UTF-8 0
2020-12-17 15:47:12.355 -08:00 [INF] Authorization failed. These requirements were not met:
DenyAnonymousAuthorizationRequirement: Requires an authenticated user.
配置Startup.cs中的功能项
app.UseRouting();
app.UseAuthorization();
app.UseAuthentication();
app.UseCookiePolicy();
app.UseStaticFiles();
app.UseSession();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<Hubs.RangeHub>("/range");
});
javascript
connection = connection || new signalR.HubConnectionBuilder()
.withUrl("/range")
.configureLogging(signalR.LogLevel.Information)
.build();
async function start()
{
try
{
await connection.start();
console.log("SignalR Connected.");
} catch (err)
{
console.log(err);
setTimeout(start, 5000);
}
};
start();
集线器正在使用 [授权] 属性
[Authorize]
public class RangeHub : Hub
当我 运行 可能导致问题的应用程序时,我在 visual studio 的调试输出中也看到了令人不安的异常数量:
Exception thrown: 'System.IO.IOException' in System.Net.Security.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Sockets.SocketException' in
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'System.Net.Sockets.SocketException' in
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Routing.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
还有其他人运行关注这个问题吗?我花了几天时间尝试不同的东西,但还没有回到核心 3,我不知道还能尝试什么。
-- 更新-- 在玩了几天之后,我尝试恢复到核心 3.1,但保留了 5.0 强制执行的 app.UseSignalR 到 app.UseEndpoints 的更改。看起来这种变化是我无法解决的主要问题。它带来了一些我不熟悉并且找不到任何信息的授权更改:
app.UseRouting();
app.UseAuthorization();
app.UseAuthentication();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<Hubs.RangeHub>("/range");
});
从 app.UseSignalR 切换到那些行。这仅用于管理用户会话。谁能指出我正确的方向?
这是糟糕的一周。问题是 app.UseAuthorization();和
app.UseAuthentication();顺序错误。他们需要看起来像这样:
app.UseAuthentication();
app.UseAuthorization();
当解决方案如此简单时令人沮丧。
我已经从 Net Core 3.1 迁移到 5.0,但更新后我无法让 signalR 连接。每当它尝试连接到集线器时,我都会收到 401 错误。
错误日志
2020-12-17 15:47:07.351 -08:00 [INF] AuthenticationScheme: Identity.Application was challenged.
2020-12-17 15:47:07.351 -08:00 [INF] Request finished HTTP/2 POST
https://blah.blah.org:5001/range/negotiate?negotiateVersion=1 text/plain;charset=UTF-8 0 - 401 0
- 4.4068ms
2020-12-17 15:47:12.355 -08:00 [INF] Request starting HTTP/2 POST
https://blah.blah.org:5001/range/negotiate?negotiateVersion=1 text/plain;charset=UTF-8 0
2020-12-17 15:47:12.355 -08:00 [INF] Authorization failed. These requirements were not met:
DenyAnonymousAuthorizationRequirement: Requires an authenticated user.
配置Startup.cs中的功能项
app.UseRouting();
app.UseAuthorization();
app.UseAuthentication();
app.UseCookiePolicy();
app.UseStaticFiles();
app.UseSession();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<Hubs.RangeHub>("/range");
});
javascript
connection = connection || new signalR.HubConnectionBuilder()
.withUrl("/range")
.configureLogging(signalR.LogLevel.Information)
.build();
async function start()
{
try
{
await connection.start();
console.log("SignalR Connected.");
} catch (err)
{
console.log(err);
setTimeout(start, 5000);
}
};
start();
集线器正在使用 [授权] 属性
[Authorize]
public class RangeHub : Hub
当我 运行 可能导致问题的应用程序时,我在 visual studio 的调试输出中也看到了令人不安的异常数量:
Exception thrown: 'System.IO.IOException' in System.Net.Security.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Sockets.SocketException' in
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll
Exception thrown: 'System.Net.Sockets.SocketException' in
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Routing.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
还有其他人运行关注这个问题吗?我花了几天时间尝试不同的东西,但还没有回到核心 3,我不知道还能尝试什么。
-- 更新-- 在玩了几天之后,我尝试恢复到核心 3.1,但保留了 5.0 强制执行的 app.UseSignalR 到 app.UseEndpoints 的更改。看起来这种变化是我无法解决的主要问题。它带来了一些我不熟悉并且找不到任何信息的授权更改:
app.UseRouting();
app.UseAuthorization();
app.UseAuthentication();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<Hubs.RangeHub>("/range");
});
从 app.UseSignalR 切换到那些行。这仅用于管理用户会话。谁能指出我正确的方向?
这是糟糕的一周。问题是 app.UseAuthorization();和 app.UseAuthentication();顺序错误。他们需要看起来像这样:
app.UseAuthentication();
app.UseAuthorization();
当解决方案如此简单时令人沮丧。