我有一个asp.net core web api服务器,正在流式传输一个signalr信号。对于asp.net客户端,它可以正常工作。我正在尝试使用下面显示的代码建立连接,但它只能连接到非核心服务器,不能与核心服务器配合工作。
//the hub class in the server code
[EnableCors("AllowAllOrigins")]
[HubName("LogNotifierHub")]
public class LogNotifierHub : Hub
{
//methods defined here
}
路由的启动代码:
app.UseSignalR(routes =>
{
routes.MapHub<LogNotifierHub>("/NotifierHub");
});
Javascript 代码用于建立连接。
var hubUrl ="http://localhost:52273/logNotifierHub";
var connection = $.hubConnection(hubUrl, { useDefaultPath: true});
var hub = connection.createHubProxy("LogNotifierHub");
hub.on('SendStreamInit', function(data){
console.log( data)
})
connection.start()
.done(function(){ console.log(' connected!! connection ID=' + connection.id); })
.fail(function(error){ console.log('Could not connect!!' + error); });
;
是可以省略的,但有时候推断机制会出错。 - undefined