Asp.net mvc 角度/信号器错误:无法启动连接。SyntaxError:JSON输入意外结束
尝试进行简单的角度/信号应用 我的集线器类:Asp.net mvc 角度/信号器错误:无法启动连接。SyntaxError:JSON输入意外结束,asp.net-mvc,angular,signalr,Asp.net Mvc,Angular,Signalr,尝试进行简单的角度/信号应用 我的集线器类: namespace Gameserver.Hubs { public class SignalRHub : Hub { public Task Send() { return Clients.All.InvokeAsync("Send", "Message from the server"); } } } my startup.cs: public pa
namespace Gameserver.Hubs
{
public class SignalRHub : Hub
{
public Task Send()
{
return Clients.All.InvokeAsync("Send", "Message from the server");
}
}
}
my startup.cs:
public partial class Startup
{
public void Configure(IAppBuilder app)
{
app.MapSignalR();
}
}
和一个组件:
import { Component, OnInit } from '@angular/core';
import { HubConnection } from '@aspnet/signalr-client';
export class CoreComponent implements OnInit
{
private connection: HubConnection;
ngOnInit(){
this.connection = new HubConnection('http://localhost:49756/signalr/');
this.connection.on('send', data =>{
console.log(data);
})
this.connection.start()
.then(() => console.log('connected'))
.catch(err => console.log('Error while establishing connection: ' + err));
}
运行后,从Loggers.js
获取此错误:
Error: Failed to start the connection. SyntaxError: Unexpected end of JSON input
有人能帮我解决这个错误吗?在尝试了另外两个软件包后,我发现其中一个工作正常。
当您通过浏览器直接访问“localhost:49756/signal/”时,是否需要任何身份验证?不,不需要。我有完全相同的问题,是的,我的集线器需要身份验证,是否需要任何解决方案?请尝试查看我的答案:该解决方案也包含身份验证数据。