【问题标题】:SignalR client not working after update to core 3.1SignalR 客户端在更新到核心 3.1 后无法正常工作
【发布时间】:2020-02-10 08:39:50
【问题描述】:

我们最近将服务器端的代码更新为 asp.net core 3.1。 现在 signalr 的 java-script 客户端存在问题 (@microsoft/signalr 3.1.0)。

我收到以下错误:

集线器初始化代码:

访问令牌工厂从 msal 返回令牌。 (没有对身份验证进行任何更改,并且在那里正确接收了令牌) 如果有人可以帮助我,那就太好了。

【问题讨论】:

  • 您是否尝试过其他传输方式?
  • 是的,我做到了,我刚刚看到长轮询正在工作。但我更喜欢使用 WebSockets。但是为什么 WebSockets 上的传输不再起作用了?我所知道的唯一改变的是 Hub 使用的是 Newtonsoft Json 协议。 @Kiril1512
  • 你的创业公司有app.UseWebSockets();吗?

标签: typescript websocket signalr asp.net-core-signalr signalr-client


【解决方案1】:

我正在使用 @aspnet/signalr javascript 客户端 - 与服务器的 Nuget 版本相同。 不知道为什么,但无法与@microsoft/signalr 一起使用。

检查您的启动,对我来说,身份验证失败,因为我忘记在 Cors 上添加 AllowCredentials:

public void ConfigureServices(IServiceCollection services)
{
        services
            .AddControllers();
        services.AddCors(options => options.AddPolicy("CorsPolicy", builder =>
        {
            builder
                .AllowAnyMethod() //edit on your requirements
                .AllowAnyHeader() //edit on your requirements
                .AllowAnyOrigin() //edit on your requirements
                .AllowCredentials();
        }));
        services.AddSignalR();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseAuthorization();
}

【讨论】:

    【解决方案2】:

    我遇到了同样的错误,最终问题出在查询参数中传递的access_token 的长度上,请参阅此问题query string is too long with big bearer token attached in the URL

    所以为了解决它检查这个answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-28
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      相关资源
      最近更新 更多