title: SignalR CORS error on request to Hub method
body: <p>I'm just trying to get SignalR setup to run owin hosted and I want to connect via the JavaScript client. Should be easy right? I was able to quickly get the SignalR server set up and running and the client connecting to the server. However, when the done callback is called on the client I try to make a call to the hubs Send method and I get the following error in the console:</p>
  
  <p>XMLHttpRequest cannot load <a href="http://localhost:8199/signalr/signalr/send?transport=serverSentEvents&amp;clien" rel="noreferrer">http://localhost:8199/signalr/signalr/send?transport=serverSentEvents&amp;clien</a>…AxBg6iaFwlK50s2DnurE&amp;connectionData=%5B%7B%22name%22%3A%22testhub%22%7D%5D. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost" rel="noreferrer">http://localhost</a>' is therefore not allowed access. The response had HTTP status code 500.</p>
  
  <p>Here is my server Side code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>    public static IAppBuilder UseService(this IAppBuilder app)
      {
          log4net.Config.XmlConfigurator.Configure();
          app.UseService(NinjectConfig.CreateKernel);
          app.UseLogging();
          app.UseSignalr();
          return app;
      }
  </code></pre>
  
  <pre class="lang-cs prettyprint-override"><code>    internal static IAppBuilder UseSignalr(this IAppBuilder app)
      {
          app.Map("/signalr", map =&gt;
              {
                 map.UseCors(CorsOptions.AllowAll);
  
                  var hubConfig = new HubConfiguration {EnableDetailedErrors = true};
                  map.RunSignalR(hubConfig);
              }
          );
          return app;
      }
  </code></pre>
  
  <p>Here is the client side: </p>
  
  <pre class="lang-js prettyprint-override"><code>    var connection = $.hubConnection('http://localhost:8199/signalr');
      var testHub = connection.createHubProxy('testHub');
  
      testHub.on('addMessage', function(name){
          console.log(name);
      });
  
      connection.start().done(function () {
              testHub.invoke('send', 'testName');
          }).fail(function (e) {
              console.log('Failed to connect');
          });
          connection.error(function(error){
          console.log(error);
      });
  </code></pre>
  
  <p>Why is the CORS request working for the start call and not the subsequent hub method call?</p>
  
  <p>Update: 
  In the network tab i can see there is a call to: <a href="http://localhost8199/signalr/negotiate" rel="noreferrer">http://localhost8199/signalr/negotiate</a> - this call works and the CORS headers are riding the response as expected </p>
  
  <p>There is then a call to: <a href="http://localhost:8199/signalr/connect" rel="noreferrer">http://localhost:8199/signalr/connect</a> and that call also has the correct CORS headers and works.</p>
  
  <p>Then there is a call to: <a href="http://localhost:8199/signalr/start" rel="noreferrer">http://localhost:8199/signalr/start</a> Same good things happen here.</p>
  
  <p>Finally there is a call to: <a href="http://localhost:8199/signalr/send" rel="noreferrer">http://localhost:8199/signalr/send</a> and this is the call that fails and there are zero CORS headers per the failure message. </p>
  
  <p>Update: </p>
  
  <p>I have also tried setting my client up like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>    $.connection.hub.url = 'http://localhost:8199/signalr';
          var proxy = $.connection.testHub;
          proxy.client.addMessage = function(name){
              console.log(name);
      };
  
      $.connection.hub.start()
      .done(function () {
          console.log($.connection.hub.id);
          proxy.server.sendMessage()
              .done(function(val){
                  console.log(val);
              });
       })
      .fail(function (e) {
          console.log('Failed to connect');
      });
  </code></pre>
  
  <p>I had little hope of this working as I feel that the issue is server side. But Just wanted to update on what I have tried here.</p>