Last active
January 26, 2021 20:00
-
-
Save lawrence-laz/af8cbbc646022c35141b79b4d187682b to your computer and use it in GitHub Desktop.
Set up CORS in ASP.NET Core on all controllers/methods.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NuGet Microsoft.AspNet.Cors (5.2.7) | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddCors(options => | |
options.AddDefaultPolicy(builder => | |
builder | |
.AllowAnyOrigin() // .WithOrigins(...) if .AllowCredentials | |
.AllowAnyMethod() | |
.AllowAnyHeader() | |
.AllowCredentials())); | |
} | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
app.UseCors(); // Order is important, look into docs. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment