From d58966117f3765d766cec0a1123943f7d213ccde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=BF=8A=E7=B9=81?= Date: Tue, 10 Nov 2020 10:23:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=A4=9A=E4=BD=99nuget?= =?UTF-8?q?=E5=8C=85=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=B7=A8=E5=9F=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8C=96=EF=BC=8C=E9=85=8D=E7=BD=AEJSON.NET=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DJObject=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj | 16 +++++++--------- APIJSON.NET/APIJSON.NET/Startup.cs | 10 ++++++++-- APIJSON.NET/APIJSON.NET/appsettings.json | 1 + 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj b/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj index ca433bf..1a23f95 100644 --- a/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj +++ b/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj @@ -19,15 +19,13 @@ - - - - - - - - - + + + + + + + diff --git a/APIJSON.NET/APIJSON.NET/Startup.cs b/APIJSON.NET/APIJSON.NET/Startup.cs index 4a0cfb6..756a23c 100644 --- a/APIJSON.NET/APIJSON.NET/Startup.cs +++ b/APIJSON.NET/APIJSON.NET/Startup.cs @@ -41,13 +41,19 @@ public void ConfigureServices(IServiceCollection services) }); AuthConfigurer.Configure(services, Configuration); + var origins = Configuration.GetSection("CorsUrls").Value.Split(","); services.AddCors( options => options.AddPolicy( _defaultCorsPolicyName, builder => - builder.AllowAnyOrigin() + builder.WithOrigins(origins) .AllowAnyHeader() .AllowAnyMethod().AllowCredentials() )); - services.AddControllers(); + services.AddControllers() + .AddNewtonsoftJson(options => + { + options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; + options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; + }); ; services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "APIJSON.NET", Version = "v1" }); diff --git a/APIJSON.NET/APIJSON.NET/appsettings.json b/APIJSON.NET/APIJSON.NET/appsettings.json index da52e61..610c96b 100644 --- a/APIJSON.NET/APIJSON.NET/appsettings.json +++ b/APIJSON.NET/APIJSON.NET/appsettings.json @@ -4,6 +4,7 @@ "ConnectionString": "Server=192.168.2.25;Database=yunwei;Uid=root;Pwd=xmjk;Port=3306;Character Set=utf8;" //"ConnectionString": "Server=119.29.9.25;Port=3306;Database=test;Uid=root;Pwd=1q,2w.3e?;CharSet=UTF8;" }, + "CorsUrls": "http://localhost:5000,http://localhost5001", "Authentication": { "JwtBearer": { "IsEnabled": "true",