XMLHttpRequest cannot load
=1377623738064″>http://localhost:8080/negotiate?connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&clientProtocol=1.3&=1377623738064.
Originhttp://localhost:7176
is not allowed by
Access-Control-Allow-Origin.
客户端站点在http:// localhost:7176上运行,并且集线器正在通过http:// localhost:8080上的控制台应用程序进行侦听.我在这里错过了什么吗?在我升级到RC1之前,跨域请求正在运行.
CONSOLE APP入口点
static void Main(string[] args) { var chatServer = new ChatServer(); string endpoint = "http://localhost:8080"; chatServer.Start(endpoint); Console.WriteLine("Chat server listening at {0}...",endpoint); Console.ReadLine(); }
CHATSERVER CLASS
public class ChatServer { public IDisposable Start(string url) { return WebApp.Start<Startup>(url); } }
启动配置
public class Startup { public void Configuration(IAppBuilder app) { app.Map("/signalr",map => { map.UseCors(CorsOptions.AllowAll); map.RunSignalR(new HubConfiguration { EnableJSONP = true }); }); } }
解决方法
XMLHttpRequest无法加载= 1377623738064“> http:// localhost:8080 / negotiate?connectionData = [{”name“:”chathub“}]& clientProtocol = 1.3& = 1377623738064.Origin http:// localhost:7176 is Access-Control-Allow-Origin不允许.
协商请求应该发送到http:// localhost:8080 / signalsr / negotiate?…不是http:// localhost:8080 / negotiate?….要解决这个问题,你可以在调用$之前尝试以下方法. connection.hub.start:
$.connection.hub.url = http:// localhost:8080 / signalsr;