From 722bc30f5465f07b6546e73401e3be9fe0a6dd04 Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Thu, 17 Oct 2019 15:59:43 +0800 Subject: Add cors. --- Timeline/Startup.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'Timeline/Startup.cs') diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 7552df2e..8e8a6393 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Cors.Infrastructure; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.EntityFrameworkCore; @@ -34,10 +35,19 @@ namespace Timeline services.Configure(Configuration.GetSection(nameof(JwtConfig))); var jwtConfig = Configuration.GetSection(nameof(JwtConfig)).Get(); - services.AddAuthentication(AuthConstants.Scheme) .AddScheme(AuthConstants.Scheme, AuthConstants.DisplayName, o => { }); + var corsConfig = Configuration.GetSection("Cors").Get(); + services.AddCors(setup => + { + setup.AddDefaultPolicy(new CorsPolicyBuilder() + .AllowAnyHeader() + .AllowAnyMethod() + .WithOrigins(corsConfig).Build() + ); + }); + services.AddScoped(); services.AddScoped(); services.AddTransient(); @@ -68,6 +78,8 @@ namespace Timeline app.UseRouting(); + app.UseCors(); + app.UseAuthentication(); app.UseAuthorization(); -- cgit v1.2.3