Created
May 8, 2021 19:46
-
-
Save Whistler092/ccb08dee8ab30cf08e5cb2f8be6ad74f to your computer and use it in GitHub Desktop.
Add Cors Dotnet core
This file contains hidden or 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
public class Startup | |
{ | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddTransient<MyActionFilter>(); | |
services.AddControllers(options => | |
/// ... | |
ervices.AddCors(options => | |
{ | |
var frontendUrl = Configuration.GetValue<string>("frontend_url"); | |
options.AddDefaultPolicy(builder => | |
{ | |
builder | |
.WithOrigins(frontendUrl) | |
.AllowAnyMethod() | |
.AllowAnyHeader(); | |
}); | |
}); | |
//... | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
//... | |
app.UseRouting(); | |
app.UseCors(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment