public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("cors", builder => { builder.WithOrigins("http://example.com", "http://www.contoso.com") .AllowAnyHeader() .AllowAnyMethod(); }); }); services.AddControllers(); }
app.UseCors("cors");
https://docs.microsoft.com/zh-cn/aspnet/core/security/cors?view=aspnetcore-5.0#cors-with-named-policy-and-middleware