title: POST request to .net core web api from Chrome is not working
body: <p>I'm working on a .net core web api project and this block giving me nightmares. I'm trying to send request from ionic-angular to .net core project. GET request is working perfectly. But the POST request is not. when i try to test the project in chrome, it says net::ERR_CONNECTION_RESET to a OPTIONS request. I understand Chrome send a preflight OPTIONS request before my real POST request. But that is the problem. I tried to handle that OPTIONS request with a Middleware like this</p>
  
  <pre>
    <code>
  
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Threading.Tasks;
      using Microsoft.AspNetCore.Builder;
      using Microsoft.AspNetCore.Http;
      using Microsoft.AspNetCore.Hosting;
  
      namespace A.Middlewares
      {
          public class OptionsMiddleware
          {
              private readonly RequestDelegate _next;
              private IHostingEnvironment _environment;
  
              public OptionsMiddleware(RequestDelegate next, IHostingEnvironment environment)
              {
                  _next = next;
                  _environment = environment;
              }
  
              public async Task Invoke(HttpContext context)
              {
                  this.BeginInvoke(context);
                  await this._next.Invoke(context);
              }
  
              private async void BeginInvoke(HttpContext context)
              {
                  if (context.Request.Method == "OPTIONS")
                  {
                      context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "http://localhost:8100" });
                      context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Origin, X-Requested-With, Content-Type, Accept" });
                      context.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "GET, POST, PUT, DELETE, OPTIONS" });
                      context.Response.Headers.Add("Access-Control-Allow-Credentials", new[] { "true" });
                      context.Response.StatusCode = 200;
                      await context.Response.WriteAsync("OK");
                  }
                  else
                  {
                      context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "http://localhost:8100" });
                      context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Origin, X-Requested-With, Content-Type, Accept" });
                      context.Response.Headers.Add("Access-Control-Allow-Credentials", new[] { "true" });
                  }
  
              }
          }
  
          public static class OptionsMiddlewareExtensions
          {
              public static IApplicationBuilder UseOptions(this IApplicationBuilder builder)
              {
                  return builder.UseMiddleware();
              }
          }
      }
  
    </code>
  </pre>
  
  <p>But it is still not helping. If there is any trick around that, enlighten me!</p>