1.增加全站api 文本日志记录,后期可扩展日志记录到ES等搜索器中
2.禁用.net自动模态验证 , 采用系统全局异常捕获机制,增加友好提示
This commit is contained in:
wangsl
2021-05-08 16:29:11 +08:00
parent a681549bd8
commit 781097f325
4 changed files with 188 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ using Autofac;
using IdentityServer4.AccessTokenValidation;
using Infrastructure;
using Infrastructure.Extensions.AutofacManager;
using Infrastructure.Middleware;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
@@ -110,14 +111,19 @@ namespace OpenAuth.WebApi
}
});
services.Configure<AppSetting>(Configuration.GetSection("AppSetting"));
services.AddControllers(option => { option.Filters.Add<OpenAuthFilter>(); }).AddNewtonsoftJson(options =>
{
//忽略循环引用
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
//不使用驼峰样式的key
//options.SerializerSettings.ContractResolver = new DefaultContractResolver();
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
});
services.AddControllers(option => { option.Filters.Add<OpenAuthFilter>(); })
.ConfigureApiBehaviorOptions(options =>
{
// 禁用自动模态验证
options.SuppressModelStateInvalidFilter = true;
}).AddNewtonsoftJson(options =>
{
//忽略循环引用
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
//不使用驼峰样式的key
//options.SerializerSettings.ContractResolver = new DefaultContractResolver();
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
});
services.AddMemoryCache();
services.AddCors();
// todo:如果正式 环境请用下面的方式限制随意访问跨域
@@ -198,6 +204,9 @@ namespace OpenAuth.WebApi
app.UseRouting();
app.UseAuthentication();
// 启用日志追踪记录和异常友好提示
app.UseLogMiddleware();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
//配置ServiceProvider