title: Cors not working in web api 2.0
body: <p>I'm trying very hard to understand and enable CORS in a web api project. I've hit a blocking point. I've started with an ASP.NET MVC Web Api 2 project with an ASP.NET identity. Whatever I do seems to not work.</p>
  
  <p>I've deleted my <code>global.asx</code> file and my startup looks like this: </p>
  
  <pre><code>public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
            HttpConfiguration configuration = new HttpConfiguration();
            // I'm not sure it this is the proper way to use webapiconfig
            WebApiConfig.Register(configuration);
            app.UseWebApi(configuration);
            app.UseCors(CorsOptions.AllowAll);
            ConfigureAuth(app);
      }
  }
  </code></pre>
  
  <p>and the WebApiConfig.Register code is: </p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
       // Web API configuration and services
       // Configure Web API to use only bearer token authentication.
       config.SuppressDefaultHostAuthentication();
       config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
       config.AddODataQueryFilter();
  
       // Web API routes
       config.MapHttpAttributeRoutes();
  
       config.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
       );
  
       var jsonFormatter = config.Formatters.OfType&lt;JsonMediaTypeFormatter&gt;().First();
       jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
       RegisterModels(); //Automapper here
  }
  </code></pre>
  
  <p>I have the mc aspnet cors and microsoft owin host System web installed.
  The "[assembly: OwinStartup(typeof(MyProject.Startup))]" is in place, and in the <code>web.config</code> I have:</p>
  
  <pre><code>&lt;appSettings&gt;
    &lt;add key="owin:AutomaticAppStartup" value="true" /&gt;          
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>I only call app.UseCors(CorsOptions.AllowAll) to enable CORS, no other way like <code>config.enableCors</code> or anything else, but whenever I try getting the token or anything in the API, I get the error:</p>
  
  <blockquote>
    <p>Reason: CORS header ‘Access-Control-Allow-Origin’ missing.</p>
  </blockquote>
  
  <p>I have tried putting a breakpoint in the <code>Configuration</code> method but it is not called... ever. I'm debugging with IIS Express. </p>