检测到与ASP.NET SignalR服务器的连接尝试.该客户端仅支持连接到ASP.NET Core SignalR服务器 [英] Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server

查看:93
本文介绍了检测到与ASP.NET SignalR服务器的连接尝试.该客户端仅支持连接到ASP.NET Core SignalR服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using a console application for a server and my client is an angular 2 app. I get an error of

错误:无法启动连接:错误:检测到与ASP.NET SignalR Server的连接尝试.该客户端仅支持连接到ASP.NET Core SignalR服务器.

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看起来像这样:

I got my hub setup and my Startup.cs looks like this:

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);
            });
        }
    }

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

and in my angular app, this is what I have in the 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核心信号器服务器,但是我该怎么做?

I know my error says to connect to asp.net core signalr server but how do i do this?

推荐答案

正如Stefano和Ibanez所说,版本"存在问题.

As Stefano and Ibanez commented is a problem with "versions".

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

The client of SignalR you are using is able to connect to ASPNET Core but not ASPNET server like error mentioned.

如果您知道ASPNET Core是基于.Net Framework(CLR)的用于多平台的产品.

If you know ASPNET Core is a split from .Net Framework (CLR) based for multiplatform.

然后在这种情况下您有两个选择.

Then you have two options over this scenario.

首先,如果您希望继续使用ASPNET服务器端,则可以更改客户端.然后将您使用的库更改为支持ASPNET的库.看一下: SIGNALR-ASPNET与ASPNET Core

First you can change your client side if you desire to continue using ASPNET server side. Then change the library you using to one that supports ASPNET. Give a look: SIGNALR - ASPNET vs ASPNET Core

第二,例如,可以更改服务器端并将ASPNET Core for SignalR用作微服务.然后继续使用ASPNET Core SignalR库实现您的客户端.

Second you can change your server side and use ASPNET Core for SignalR, as a microservice, for example. Then continue implementing your client with ASPNET Core SignalR library.

这篇关于检测到与ASP.NET SignalR服务器的连接尝试.该客户端仅支持连接到ASP.NET Core SignalR服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆