title: Access-Control-Allow-Origin error when using Owin
body: <p>I'm have a aurelia client and a webserver. When i use localhost and i'm running on the same machine it works fine.</p>
  
  <p>But when i want to access the server from another machine the page loads but the api calls give the following error:
  No <code>Access-Control-Allow-Origin</code> header is present on the requested resource.</p>
  
  <p>I'm using owin and to my undestanding i need to enable CORS for owin.</p>
  
  <p>I did the follwing in my startup class:-</p>
  
  <p>UPDATE
  I have updated my class with input from Nenad but is still get the same error.
  Below i have added the call from the client.</p>
  
  <pre><code> public void Configuration(IAppBuilder app)
          {
  
              this.container = new Container();
              // Create the container as usual.
              container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
  
              // Register your types, for instance using the scoped lifestyle:
              container.Register&lt;IWebDeps, WebDeps&gt;(Lifestyle.Singleton);
  
              // This is an extension method from the integration package.
              container.RegisterWebApiControllers(GlobalConfiguration.Configuration, Assembly.GetExecutingAssembly());
  
              container.Verify();
  
              app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
  
              // Configure Web API for self-host. 
              var config = new HttpConfiguration()
              {
                  DependencyResolver =
                  new SimpleInjectorWebApiDependencyResolver(container)
              };
  
              var cors = new EnableCorsAttribute("*", "*", "*");
              config.EnableCors(cors);
  
              config.MapHttpAttributeRoutes();
              config.Routes.MapHttpRoute(
                  name: "DefaultApi",
                  routeTemplate: "api/{controller}/{id}",
                  defaults: new { id = RouteParameter.Optional }
              );
              //// Custom Middleare
              app.Use(typeof(CustomMiddleware));
              app.UseWebApi(config);
  
              //New code:
              app.Run(context =&gt;
              {
                  context.Response.ContentType = "text/plain";
                  return context.Response.WriteAsync("Hello, world.");
              });
          }   
  </code></pre>
  
  <p>My main program is calling the startUp class:-</p>
  
  <pre><code>  using (Microsoft.Owin.Hosting.WebApp.Start&lt;Startup&gt;("http://localhost:8080"))
              {
                  Console.WriteLine("Press [enter] to quit...");
                  Console.ReadLine();
              }
  </code></pre>
  
  <p>Client code, 192.168.178.23 is the ip from the server. </p>
  
  <pre><code>let baseUrl2 = "http://192.168.178.23:8080/api/status/getStatus";
      getStatus() {
          return this.client.get(baseUrl2)
              .then(response =&gt; {
                  return this.parseJSONToObject(response.content);
          });
      }
  </code></pre>
  
  <p>The error in Chrome:</p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load
    <a href="http://192.168.178.23:8080/api/status/getStatus" rel="nofollow noreferrer">http://192.168.178.23:8080/api/status/getStatus</a>. No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin '<a href="http://localhost:9000" rel="nofollow noreferrer">http://localhost:9000</a>' is therefore not allowed
    access. The response had HTTP status code 400.</p>
  </blockquote>
  
  <p>Cors should be enabled now right? But i still get the error when doing a api call. Am i missing any steps? Our is this approah wrong? </p>
  
  <p>Any suggestions are welcome!</p>