从javascript客户端连接到asp.net核心SignalR服务器 [英] connet to asp.net core signalR server from a javascript client
本文介绍了从javascript客户端连接到asp.net核心SignalR服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个asp.net核心网络api服务器正在流式传输信号器,并且它适用于asp.net客户端,我正在尝试与显示如下的代码建立连接,但它仅连接到不会的非核心服务器为核心服务器工作.
I have asp.net core web api server that is streaming a signalr, And it works for asp.net client , I am trying to make a connection with the code showen beelow but it only connects to a none core servers it wouldnt work for the core servers.
//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); });
推荐答案
您不能混合使用SignalR服务器和客户端的版本.如果您在服务器上使用核心,则也必须在客户端上使用它.
You can't mix and match version of the SignalR server and client. If you're using core on the server then you have to use it on the client as well.
查看全文