title: Enable CORS in Web API 2
body: <p>I have client and a server running on different ports. The server is running <strong>Web API 2 (v5.0.0-rc1)</strong>.</p>
  
  <p>I tried installing the <a href="http://www.nuget.org/packages/Microsoft.AspNet.WebApi.Cors/">Microsoft ASP.NET Web API Cross-Origin Support package</a> and enabled it in <code>WebApiConfig.cs</code>. It gives me the <code>EnableCors()</code> function, so the package was installed correctly.</p>
  
  <p>Here you can see my <code>Register()</code> function in <code>WebApiConfig.cs</code>:</p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
      config.MapHttpAttributeRoutes();
  
      var cors = new EnableCorsAttribute("*", "*", "*");
      config.EnableCors(cors);
  }
  </code></pre>
  
  <p><code>GET</code> requests work fine. But when sending <code>POST</code>, I get the following:</p>
  
  <pre><code>OPTIONS http://localhost:19357/api/v1/rooms? 404 (Not Found) angular.js:10159
  OPTIONS http://localhost:19357/api/v1/rooms? Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin. angular.js:10159
  XMLHttpRequest cannot load http://localhost:19357/api/v1/rooms. Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.
  </code></pre>
  
  <p>According to Fiddler it only sends the <code>OPTIONS</code> request. It doesn't issue the <code>POST</code> afterwards.</p>
  
  <p>So I'm guessing the <code>config.EnableCors(cors);</code> in the <code>WebApiConfig.cs</code> isn't doing anything, which leads to the server denying the client/browser to send a <code>POST</code> request.</p>
  
  <p>Do you have any idea how to solve this problem?</p>
  
  <p><strong>EDIT 05.09.13</strong> 
  This has been fixed in 5.0.0-rtm-130905</p>