无法从 javascript signalr 客户端连接到 azure 客户端

Not able to connect from javascript signalr client to azure client

这是我的东西:

Javascript:

 var connection = new signalR.HubConnectionBuilder()
                .configureLogging(signalR.LogLevel.Debug)
                .withUrl("/client/?hub=myHub")
                .withAutomaticReconnect().build();

 var connection = new signalR.HubConnectionBuilder()
                .configureLogging(signalR.LogLevel.Debug)
                .withUrl("https://azure-service.service.signalr.net/client/?hub=myHub")
                .withAutomaticReconnect().build();

C#Startup.cs:

    // Azure SignalR service
    app.UseAzureSignalR(routes =>
    {
        routes.MapHub<MyHub>("/myHub");
    });

出现以下错误: 400 - https://localhost:44324/client/negotiate?hub=myHub&negotiateVersion=1 无法完成与服务器的协商:错误

您需要在 appsettings.json 中添加 ConnectionString。这个对我有用。您也可以 download my sample code.