Tutorial by Examples

Use the UseCors() extension method on the IApplicationBuilder in the Configure method to apply the CORS policy to all requests. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddCors(); } public void Configure(IApplicationBuilder app) { ...
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() ...
The policy builder allows you to build sophisticated policies. app.UseCors(builder => { builder.WithOrigins("http://localhost:5000", "http://myproductionapp.com") .WithMethods("GET", "POST", "HEAD") .WithHeaders(&quo...
To enable a CORS policy across all of your MVC controllers you have to build the policy in the AddCors extension within the ConfigureServices method and then set the policy on the CorsAuthorizationFilterFactory using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Cors.Internal; ... pub...

Page 1 of 1