How to enable CORS in ASP.NET Core

前端 未结 12 834
无人及你
无人及你 2020-11-22 14:11

I am trying to enable cross origin resources sharing on my ASP.NET Core Web API, but I am stuck.

The EnableCors attribute accepts policyName

12条回答
  •  佛祖请我去吃肉
    2020-11-22 14:34

    You have to configure in Startup.cs class

    services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                    builder => builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials());
            });
    

提交回复
热议问题