Skip to content

Commit 0525f90

Browse files
authored
Merge pull request liaozb#22 from fanslead/master
移除多余nuget包,添加跨域配置化,配置JSON.NET修复JObject报错
2 parents 20851c5 + d589661 commit 0525f90

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj

+7-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.4" />
23-
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
24-
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="2.2.0" />
25-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="2.2.0" />
26-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
27-
28-
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
29-
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.4.1" />
30-
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.4.1" />
22+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" />
23+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.9" />
24+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
25+
26+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
27+
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.6.3" />
28+
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.6.3" />
3129
</ItemGroup>
3230

3331
<ItemGroup>

APIJSON.NET/APIJSON.NET/Startup.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ public void ConfigureServices(IServiceCollection services)
4141
});
4242
AuthConfigurer.Configure(services, Configuration);
4343

44+
var origins = Configuration.GetSection("CorsUrls").Value.Split(",");
4445
services.AddCors( options => options.AddPolicy( _defaultCorsPolicyName,
4546
builder =>
46-
builder.AllowAnyOrigin()
47+
builder.WithOrigins(origins)
4748
.AllowAnyHeader()
4849
.AllowAnyMethod().AllowCredentials()
4950
));
50-
services.AddControllers();
51+
services.AddControllers()
52+
.AddNewtonsoftJson(options =>
53+
{
54+
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
55+
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
56+
}); ;
5157
services.AddSwaggerGen(c =>
5258
{
5359
c.SwaggerDoc("v1", new OpenApiInfo { Title = "APIJSON.NET", Version = "v1" });

APIJSON.NET/APIJSON.NET/appsettings.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ConnectionString": "Server=192.168.2.25;Database=yunwei;Uid=root;Pwd=xmjk;Port=3306;Character Set=utf8;"
55
//"ConnectionString": "Server=119.29.9.25;Port=3306;Database=test;Uid=root;Pwd=1q,2w.3e?;CharSet=UTF8;"
66
},
7+
"CorsUrls": "http://localhost:5000,http://localhost5001",
78
"Authentication": {
89
"JwtBearer": {
910
"IsEnabled": "true",

0 commit comments

Comments
 (0)