在Angular 5和Asp.net WebApi上使用信号器
我实际上是在ASP.NET框架API上创建一个与angular 5和signalR的聊天。我遵循了文档,但仍然不起作用。这是我的中心:在Angular 5和Asp.net WebApi上使用信号器,asp.net,asp.net-mvc,angular,asp.net-web-api,signalr,Asp.net,Asp.net Mvc,Angular,Asp.net Web Api,Signalr,我实际上是在ASP.NET框架API上创建一个与angular 5和signalR的聊天。我遵循了文档,但仍然不起作用。这是我的中心: public class ChatHub : Hub { public void Hello() { Clients.All.hello(); } } 这是我的创业课程: app.Map("/signalr", map => { // Setup t
public class ChatHub : Hub
{
public void Hello()
{
Clients.All.hello();
}
}
这是我的创业课程:
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
{
EnableJSONP = true
};
// Run the SignalR pipeline. We're not using MapSignalR
// since this branch already runs under the "/signalr"
// path.
map.RunSignalR(hubConfiguration);
});
这是我创建轮毂连接的角度部分:
ngOnInit() {
this._hubConnection = new HubConnection('http://localhost:58525/signalr/hubs');
this._hubConnection
.start()
.then(() => console.log('Connection started!'))
.catch(err => console.log('Error while establishing connection :( : ' + err));
this._hubConnection.on('send', data => {
console.log(data);
});
}
我得到这个错误:如果您的ASP.NET页面在另一台服务器上运行,则您的URL看起来不正确 您必须连接到:
this._hubConnection = new HubConnection('http://localhost:58525/signalr');