To enable a certain CORS policy for specific controllers you have to build the policy in the AddCors
extension within the ConfigureServices
method:
services.AddCors(cors => cors.AddPolicy("AllowAll", policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));
This allows you to apply the policy to a controller:
[EnableCors("AllowAll")]
public class HomeController : Controller
{
// ...
}