SignalR 1.0.1 Cross-domain request (CORS) with Chrome

前端 未结 2 1232
猫巷女王i
猫巷女王i 2020-12-18 01:47

I am trying to implement the Cross-domain calls with SignalR 1.0.1 with Chrome (Ver 25.0.1364.172). As I have my UI in one host (localhost:16881) and the \'service\' in anot

2条回答
  •  醉酒成梦
    2020-12-18 02:14

    You don't need to use

    jQuery.support.cors = true;

    Instead you can enable CORS support on your Startup class on Configuration method. Here is some of the example:

            // Branch the pipeline here for requests that start with "/signalr"
            app.Map("/signalr", map =>
            {
                // Setup the CORS middleware to run before SignalR.
                // By default this will allow all origins. You can 
                // configure the set of origins and/or http verbs by
                // providing a cors options with a different policy.
                map.UseCors(CorsOptions.AllowAll);
                var hubConfiguration = new HubConfiguration 
                {
                    // You can enable JSONP by uncommenting line below.
                    // JSONP requests are insecure but some older browsers (and some
                    // versions of IE) require JSONP to work cross domain
                    // EnableJSONP = true
                };
                // Run the SignalR pipeline. We're not using MapSignalR
                // since this branch already runs under the "/signalr"
                // path.
                map.RunSignalR(hubConfiguration);
            });
    

提交回复
热议问题