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

我与影子孤独终老i 提交于 2021-02-07 12:52:13

问题


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?


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/53861944/detected-a-connection-attempt-to-an-asp-net-signalr-server-this-client-only-sup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!