Sagar Chaudhary Sagar Chaudhary - 1 year ago 74
ASP.NET (C#) Question

I am migrating my web api to core. Cors migration

In my project i have defined cors in webapiconfig file like this

public static class WebApiConfig
public static void Register(HttpConfiguration config)
// New code
var cors = new EnableCorsAttribute("*", "*", "*", "DataServiceVersion, MaxDataServiceVersion") { SupportsCredentials = true };

Now I want to migrate it to core. How can it be done? Please help.

Answer Source
  1. Add the CORS services:

    public void ConfigureServices(IServiceCollection services)
        services.AddCors(options => options.AddPolicy("AllowAll", builder =>
                .WithExposedHeaders("DataServiceVersion", "MaxDataServiceVersion");
  2. Use the CORS middleware:

    public void Configure(IApplicationBuilder app)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download