title: connect to signalr hub
body: <p>I have created a simple SignalR hub inside a console application:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args) 
      {    
          using (WebApp.Start&lt;Startup&gt;("http://localhost:1968"))
          {
              Console.WriteLine("Server running!");        
              Console.ReadLine();    
          } 
      } 
  }
  
  public static class UserHandler
  {
      public static HashSet&lt;string&gt; ConnectedIds = new HashSet&lt;string&gt;();
  }
  
  [HubName("echo")]
  public class EchoHub : Hub 
  { 
      public void Say(string message) 
      { 
          Trace.WriteLine("hub: "+message);
          Clients.All.AddMessage(message);
      }
  
      public override Task OnConnected()
      {
          UserHandler.ConnectedIds.Add(Context.ConnectionId);
          return base.OnConnected();
      }
  
      public override Task OnDisconnected()
      {
          UserHandler.ConnectedIds.Remove(Context.ConnectionId);
          return base.OnDisconnected();
      }
  }
  
  class Startup 
  { 
      public void Configuration(IAppBuilder app) 
      { 
          app.MapSignalR();
      } 
  } 
  </code></pre>
  
  <p></p>
  
  <p>When I try to connect this from a Silverlight App, it succeeds:</p>
  
  <pre><code>static Microsoft.AspNet.SignalR.Client.HubConnection signalR { get; set; }
  public static Microsoft.AspNet.SignalR.Client.IHubProxy signalRhub { get; set; }
  
  public static void StartSignalR()
  {
      var url = "http://localhost:1968";
      signalR = new Microsoft.AspNet.SignalR.Client.HubConnection(url);
      signalR.Received += signalR_Received;
      signalRhub = signalR.CreateHubProxy("echo");
      signalR.Start().Wait();
      signalRhub.Invoke("Say", "hub invoked");
  }
  </code></pre>
  
  <p>My next step is to connect the SignalR hub from jquery:</p>
  
  <pre><code>&lt;script src="../Scripts/jquery-1.6.4.js"&gt;&lt;/script&gt;
  &lt;script src="../Scripts/jquery.signalR-2.1.0.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      $(function ()
      {
          var connection = $.hubConnection("http://localhost:1968");
          connection.start()
              .done(function () {
                  console.log('connected');
                  connection.send("success?");
              })
              .fail(function (a) {
                  console.log('not connected'+a);
              });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>When I try to run this script, it gives the error:</p>
  
  <pre><code>"XMLHttpRequest cannot load localhost:1968/signalr/negotiate?clientProtocol=1.4&amp;_=1404978593482. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin &lt;code&gt;http://localhost:55282&lt;/code&gt; is therefore not allowed access."
  </code></pre>
  
  <p>Why can I connect to the hub from my Silverlight page (hosted in localhost:3926)<br/>
  and fails it when I run the jquery script (hosted in localhost:55282)?</p>
  
  <p>What can I do to get a working connection between my jQuery and SignalR hub?</p>