title: How to enable CORS in ASP.NET Core Preflight
body: <p>I’m working with ASP.NET Core. Created the API Controller to handle Create, Get, Delete etc.  I want to be able to call he APIs from Angualr2 and finally Nativescript as an APP. Set the Cors in ConfigureServices of startup as follows:</p>
  
  <pre><code> #region Cors
          //allows Cors for API 
          //NB: must procede any endpoints
          services.AddCors(o =&gt; o.AddPolicy("AllowAll", builder =&gt;
          {
              builder.AllowAnyOrigin()
                     .AllowAnyMethod()
                     .AllowAnyHeader()
                     .AllowCredentials()
                     .SetPreflightMaxAge(TimeSpan.FromSeconds(2520))
                     .Build();
          }));
          // Apply as default to all controllers. API etc
          services.Configure&lt;MvcOptions&gt;(options =&gt;
          {
              options.Filters.Add(new CorsAuthorizationFilterFactory("AllowAll"));
          });
          #endregion
  </code></pre>
  
  <p>Then referenced posy in the controller and actions:</p>
  
  <pre><code>[Produces("application/json")]
  [Route("api/recipes")]
  [EnableCors("AllowAll")]
  </code></pre>
  
  <p>and also </p>
  
  <pre><code>// DELETE: api/5
      [HttpDelete("{id}")]
      [EnableCors("AllowAll")]
      public async Task&lt;IActionResult&gt; DeleteRecipe([FromRoute] int id)
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          Recipe.Models.Recipe recipe = await _context.Recipe.SingleOrDefaultAsync(m =&gt; m.RecipeID == id);
          if (recipe == null)
          {
              return NotFound();
          }
  
          _context.Recipe.Remove(recipe);
          await _context.SaveChangesAsync();
  
          return Ok(recipe);
      }
  </code></pre>
  
  <p>Everything works save for delete method. I get 405 method not allowed. This however works if hosting server and client are on the same domain (i.e. Localhost testing). The issue as I understand it is the preflight checks. What am I missing. Please note this is .Net Core and different from prev. versions of asp.net where u can simply create in web.config. Which incidentally I tried creating double entries in header</p>