简体   繁体   中英

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

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

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.

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

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

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

Have you solved your issue? As mentioned by JohnB, this is likely an issue of a core client trying to access a .NET framework hub.

If you're trying to connect to a .NET framework hub, you're gonna want to use the signalr package.

Otherwise, if you're hub is a .NET core application, you'll instead want to use @aspnet/signalr .

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

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

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

Then you have two options over this scenario.

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

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.

Not sure about but your problem is related to the client library you are using

The error occurs because new SignalR does not allow you to use old server & new client or new server & old client look this and this

Your possible status:

According to your example, 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

In your case, you used HubConnectionBuilder , so you wrote the new core singleR. The reason for the error may be that the referenced library is outdated.

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

Possible Solution:

Update

@aspnet/signalr-client

to

@aspnet/signalr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM