[英]Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server
我正在使用服务器的控制台应用程序,我的客户端是一个角度2应用程序。 我得到一个错误
错误:无法启动连接:错误:检测到对ASP.NET SignalR服务器的连接尝试。 此客户端仅支持连接到ASP.NET Core SignalR服务器。
我得到了集线器设置,我的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);
});
}
}
在我的角度应用程序中,这是我在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框架集线器,那么您将需要使用signalr软件包。
否则,如果您的集线器是.NET核心应用程序,那么您将需要使用@ aspnet / signalr 。
正如Stefano和Ibanez评论的那样是“版本”的问题。
您正在使用的SignalR的客户端能够连接到ASPNET Core而不是ASPNET服务器,如提到的错误。
如果您知道ASPNET Core是基于多平台的.Net Framework(CLR)的拆分。
那么你在这个场景中有两个选择。
首先,如果您希望继续使用ASPNET服务器端,可以更改客户端。 然后将您使用的库更改为支持ASPNET的库。 看看: SIGNALR - ASPNET与ASPNET核心
其次,您可以更改服务器端并使用ASPNET Core for SignalR,例如,作为微服务。 然后继续使用ASPNET Core SignalR库实现您的客户端。
不确定,但您的问题与您正在使用的客户端库有关
发生此错误是因为新的SignalR不允许您使用旧服务器和新客户端或新服务器和旧客户端 看这个和这个
您的可能状态:
根据你的例子, 像这样他试图用Angular 5连接到旧的单一服务器。我们可以理解它如何尝试获取HubConnection实例: 看看这里
在您的情况下,您使用了HubConnectionBuilder ,因此您编写了新的核心singleR。 错误的原因可能是引用的库已过时。
import {Component, OnInit} from '@ angular / core';
import {HubConnection} from '@ aspnet / signalr-client';
可能解决方案
更新
@ ASPNET / signalr客户端
至
@ ASPNET / signalr
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.