检测到与 ASP.NET SignalR 服务器的连接尝试。此客户端仅支持连接到 ASP.NET 核心 SignalR 服务器

Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server

我正在为服务器使用控制台应用程序,我的客户端是一个 angular 2 应用程序。我收到

错误

Error: Failed to start the connection: Error: Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server.

我设置了集线器,我的 Startup.cs 看起来像这样:

public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Branch the pipeline here for requests that start with "/signalr"
            app.Map("/signalr", map =>
            {
                // Setup the CORS middleware to run before SignalR.
                // By default this will allow all origins. You can 
                // configure the set of origins and/or http verbs by
                // providing a cors options with a different policy.
                map.UseCors(CorsOptions.AllowAll);
                var hubConfiguration = new HubConfiguration
                {
                    // You can enable JSONP by uncommenting line below.
                    // JSONP requests are insecure but some older browsers (and some
                    // versions of IE) require JSONP to work cross domain
                    // EnableJSONP = true
                };
                // Run the SignalR pipeline. We're not using MapSignalR
                // since this branch already runs under the "/signalr"
                // path.

                hubConfiguration.EnableDetailedErrors = true;
                map.RunSignalR(hubConfiguration);
            });
        }
    }

在我的 angular 应用程序中,这就是我在 app.component.ts

中的内容
ngOnInit(): void {
    this.nick = window.prompt('Your name:', 'John');

    this.hubConnection = new HubConnectionBuilder().withUrl("http://localhost:8089/signalr").build();

    this.hubConnection
      .start()
      .then(() => console.log('Connection started!'))
      .catch(err => console.log('Error while establishing connection :('));

    this.hubConnection.on('addMessage', (nick: string, receivedMessage: string) => {
      const text = `${nick}: ${receivedMessage}`;
      this.messages.push(text); 
    });
  }

  public sendMessage(): void {
    this.hubConnection
      .invoke('sendToAll', this.nick, this.message)
      .catch(err => console.error(err));
  }

我知道我的错误是连接到 asp.net 核心信号服务器,但我该怎么做?

你的问题解决了吗?正如 JohnB 所提到的,这可能是核心客户端试图访问 .NET 框架中心的问题。

如果您尝试连接到 .NET Framework 中心,则需要使用 signalr 包。

否则,如果您的集线器是 .NET 核心应用程序,您将需要使用 @aspnet/signalr

正如 Stefano 和 Ibanez 评论的那样,"versions" 存在问题。

您正在使用的 SignalR 客户端能够连接到 ASPNET Core,但不能连接到 ASPNET 服务器,就像提到的错误一样。

如果您知道 ASPNET Core 是从基于多平台的 .Net Framework (CLR) 中分离出来的。

那么在这种情况下你有两种选择。

如果您想继续使用 ASPNET 服务器端,首先可以更改客户端。 然后将您使用的库更改为支持 ASPNET 的库。 举个例子:SIGNALR - ASPNET vs ASPNET Core

其次,您可以更改服务器端并将 ASPNET Core 用于 SignalR,例如作为微服务。然后继续使用 ASPNET Core SignalR 库实现您的客户端。

不确定,但您的问题与您使用的客户端库有关

错误发生是因为新的SignalR不允许你使用old server & new client or new server &老客户look this and this

您的可能状态:

根据你的例子,like this he tried to connect to the old singleR server with Angular 5. We can understand from how it tries to get the HubConnection instance: look here

在您的例子中,您使用了 HubConnectionBuilder,因此您编写了新的核心 singleR。报错的原因可能是引用的库已经过时

import {Component, OnInit} from '@ angular / core';
import {HubConnection} from '@ aspnet / signalr-client';

可能的解决方案:

更新

@aspnet/signalr-client

@aspnet/signalr