Enable CORS in .NET Core Web API

// Startup.cs

public void ConfigureServices(IServiceCollection services)
{
        // ...
        CorsConfig(services);
        // ...
}

public void Configure(IApplicationBuilder app, IApiVersionDescriptionProvider provider)
{
        // ...
        CorsConfig(app);        
        // ...
}

readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
private void CorsConfig(IApplicationBuilder app)
{
    app.UseCors(MyAllowSpecificOrigins);
}
private void CorsConfig(IServiceCollection services)
{
    services.AddCors(options =>
    {
        options.AddPolicy(MyAllowSpecificOrigins,
        builder =>
        {
            builder.WithOrigins("http://localhost.com");
        });
    });
}