title: Transport Error in Google Chrome
body: <p>I am getting an error in Chrome when calling a webservice on my own box.  The error is:</p>
  
  <pre><code>Origin http://localhost:52386 is not allowed by Access-Control-Allow-Origin.
  </code></pre>
  
  <p>I have read other questions <a href="https://stackoverflow.com/questions/10143093/origin-is-not-allowed-by-access-control-allow-origin" title="here">here</a> and articles like this: <a href="http://www.cypressnorth.com/blog/programming/cross-domain-ajax-request-with-json-response-for-iefirefoxchrome-safari-jquery/" rel="nofollow noreferrer">Cross Domain AJAX</a>; but they tend to deal with the problem of IE not working correctly and I have a problem with Chrome.</p>
  
  <p>I added the following to my webservice/Global.asax.cs:</p>
  
  <pre><code>protected void Application_BeginRequest(object sender, EventArgs e)
  {
      //HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
      // Changed to this:
      HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost:52386");
      HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost:80");
  
  }
  </code></pre>
  
  <p>Here is my HTML code (I need to keep this in plain HTML, no code behind):</p>
  
  <pre><code>    $(document).ready(function () {
          var user = 'testuser';
          var pwd = 'abc123';
          var auth = 'Basic ' + Base64.encode(user + ':' + pwd);
          if ($.browser.msie) {
              jQuery.support.cors = true;
              $.ajax({
                  type: "GET",
                  url: "http://localhost/Website.Webservice/api/TaxDocument",
                  data: "{}",
                  contentType: "application/json; charset=utf-8",
                  dataType: "text json",
                  headers: { Authorization: auth },
                  crossDomain: true,
                  success: function (data, textStatus, jqXHR) { ProcessOutput(data); },
                  error: function (jqXHR, textStatus, errorThrown) { alert('Error: ' + textStatus + ' ' + errorThrown); }
              });
          } else {
              $.ajax({
                  type: "GET",
                  url: "http://localhost/Website.Webservice/api/TaxDocument",
                  data: "{}",
                  contentType: "application/json; charset=utf-8",
                  crossDomain: true,
                  dataType: "json",
                  headers: { Authorization: auth },
                  success: function (data, textStatus, jqXHR) { ProcessOutput(data); },
                  error: function (jqXHR, textStatus, errorThrown) { alert('Error: ' + textStatus + ' ' + errorThrown); }
              });
          }
      })
  </code></pre>