【发布时间】:2017-06-07 04:35:51
【问题描述】:
我从 signalr 开始,但遇到了一些问题,我的测试服务器运行在 http://localhost:22660/,我的网络运行在 http://localhost:61963/.I 从客户端连接到服务器时出现此错误:
我已经配置了:$.connection.hub.url = 'http://localhost:22660/signalr';但不行,这是我的js代码:
var connection = $.hubConnection();
$.connection.hub.url = 'http://localhost:22660/signalr';
var chatHub = connection.createHubProxy('ChatHub');
connection.start()
.done(function () { console.log('Now connected, connection ID=' + connection.id); })
.fail(function () { console.log('Could not connect'); });
服务器:
namespace test
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration
{
EnableJSONP = true
};
map.RunSignalR(hubConfiguration);
});
}
}
}
namespace SignalRChat
{
public class ChatHub : Hub
{
public void Send(string name, string message)
{
// Call the addNewMessageToPage method to update clients.
Clients.All.addNewMessageToPage(name, message);
}
}
}
【问题讨论】:
-
您的网站 什么 在 localhost:61963 上运行?请参阅minimal reproducible example,并遵循那里的指南
-
它只是清空 .NET 网站,包含 index.hmtl 和 jquery,包括信号器库
-
请发布集线器的服务器端代码,以及您注册集线器的位置。
-
@J.N.刚刚添加
标签: javascript c# signalr