Signalr 信号器连接失败:WebSocket连接失败:。错误:无法启动连接:null

Signalr 信号器连接失败:WebSocket连接失败:。错误:无法启动连接:null,signalr,asp.net-core-webapi,signalr-hub,signalr.client,asp.net-core-signalr,Signalr,Asp.net Core Webapi,Signalr Hub,Signalr.client,Asp.net Core Signalr,我的前端控制台显示此错误:WebSocket连接到'wss://localhost:5001/grouphub'失败:。错误:无法启动连接:null startup.ConfigureServices代码为: public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("

我的前端控制台显示此错误:WebSocket连接到'wss://localhost:5001/grouphub'失败:。错误:无法启动连接:null

startup.ConfigureServices代码为:

public void ConfigureServices(IServiceCollection services)
{
        services.AddCors(options =>
        {
            options.AddPolicy("AllowOrigin",
                              options =>
                              {
                                  options.AllowAnyOrigin();
                                  options.AllowAnyHeader();
                                  options.AllowAnyMethod();
                              });
        });
        services.AddSignalR();
        services.AddMvc();
}
启动的代码。配置为:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseCors("AllowOrigin");
        app.UseHttpsRedirection();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();
        app.UseCustomMiddleware();
        //app.UseStaticFiles();
        app.UseFileServer();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
            endpoints.MapHub<GroupHub>("/grouphub");
        });
    }
我没有收到任何CORS错误,而且当我让信号器选择传输类型时,它仍然不起作用


请给我一些建议。

您是否也在前端控制台中看到CORS错误?在您的代码中,我们可以发现您限制客户端仅使用
WebSocket
作为传输,如果您尝试使用其他传输或让信号器自动选择最佳传输方式,它是否可以连接到集线器?
public startConnection() {
this.collectionHubConnection = new signalR.HubConnectionBuilder()
  .withUrl("https://localhost:5001/grouphub", {
    skipNegotiation: true,
    transport: signalR.HttpTransportType.WebSockets
  }).build();
this.collectionHubConnection.start()
  .then(() => console.log("collection SIGNALR CONN DONE"))
  .catch(err => console.log("collection SIGNALR ERROR:" + err));
}
loadPatientCollection() {
this.collectionHubConnection.on("patientcollist", (data) => {
  this.insurancedb1 = data
  console.log("patient collection data", data);
})
}