SignalR 1.0.1 Requête sur plusieurs domaines (CORS) avec Chrome

J’essaie d’implémenter les appels interdomaines avec SignalR 1.0.1 avec Chrome (Ver 25.0.1364.172). Comme j’ai mon interface utilisateur dans un hôte (localhost: 16881) et le «service» dans un autre hôte (localhost: 16901).

J’ai tout en place comme dans la rubrique Comment utiliser des connexions inter-domaines (CORS – Contrôle d’origine, autoriser l’origine) avec SignalR

add jQuery.support.cors = true; before opening a connection set up $.connection.hub.url = 'http://localhost:16901/signalr';, pointing to your subdomain allow cross-domain requests on server side, by adding the following header description:  inside system.WebServer/httpProtocol/customHeaders section in Web.config file. 

J’ai également la configuration HubConfiguration pour mon mappage de route dans global.asax pour SignalR 1.0.1

  RouteTable.Routes.MapHubs(new HubConfiguration() { EnableCrossDomain = true }); 

Tout semble bien dans IE10 et FF22. Cependant, dans Chrome, cela me donne un malheur lorsque SignalR essaie de faire la poignée de main.

 XMLHttpRequest cannot load http://localhost:16901/signalr/negotiate?_=1363560032589. Origin http://localhost:16881 is not allowed by Access-Control-Allow-Origin. 

Je sais que je peux obtenir que cela fonctionne avec Chrome en le lançant avec –disable-web-security, mais cela ne correspond pas vraiment à mes besoins. S’il vous plaît aider!

Voici ce que vous devez faire:

  1. Supprimer jQuery.support.cors = true
  2. Supprimer

Alors ça devrait marcher.

Vous n’avez pas besoin d’utiliser

jQuery.support.cors = true;

Au lieu de cela, vous pouvez activer le support CORS sur votre méthode de classe de démarrage sur la configuration. Voici quelques exemples:

  // 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); });