Skip to content

Instantly share code, notes, and snippets.

@Whistler092
Created May 8, 2021 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Whistler092/ccb08dee8ab30cf08e5cb2f8be6ad74f to your computer and use it in GitHub Desktop.
Save Whistler092/ccb08dee8ab30cf08e5cb2f8be6ad74f to your computer and use it in GitHub Desktop.
Add Cors Dotnet core
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