SignalR 跨域设置


1.永久连接跨域设置

服务器端

//允许永久连接跨域
app.Map("/spy",map=> {
    map.UseCors(CorsOptions.AllowAll);
    //启用JSONP
    var config = new ConnectionConfiguration() {
        EnableJSONP=true
    };
    map.RunSignalR(config);
});

客户端

2.Hub集线器设置

服务器端

[assembly: OwinStartup(typeof(SignalRChat.Startup))]
namespace SignalRChat
{
    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);
            });
        }
    }
}
客户端

我试图用signalr跨域但我得到错误消息调用Start函数时。错误消息"Uncaught TypeError: Cannot call method 'start' of undefined "
有你的signalr连接初始化和启动的问题,同时宣布代理参考中心。看下面的例子:




    
    
    


    






另一件事,我不知道你为什么要使用不同版本的SignalR在你的服务器端和客户端。对我来说你有SignalR 2.x在你的服务器端和SignalR 1.1.4在你的有效方。

你可能感兴趣的:(Asp.net,SignalR)