@@ -46,7 +46,7 @@ public Startup(IConfiguration configuration)
46
46
// This method gets called by the runtime. Use this method to add services to the container.
47
47
public void ConfigureServices ( IServiceCollection services )
48
48
{
49
- //初始化模型验证配置
49
+ //初始化模型验证配置
50
50
services . UseMethodsModelParameters ( ) . UseMethodsGeneralParameters ( ) ;
51
51
services . AddSingleton < IObjectModelValidator > ( new NullObjectModelValidator ( ) ) ;
52
52
Services = services ;
@@ -76,13 +76,13 @@ public void ConfigureServices(IServiceCollection services)
76
76
{
77
77
options . TokenValidationParameters = new TokenValidationParameters
78
78
{
79
- SaveSigninToken = true , //保存token,后台验证token是否生效(重要)
80
- ValidateIssuer = true , //是否验证Issuer
81
- ValidateAudience = true , //是否验证Audience
82
- ValidateLifetime = true , //是否验证失效时间
83
- ValidateIssuerSigningKey = true , //是否验证SecurityKey
79
+ SaveSigninToken = true , //保存token,后台验证token是否生效(重要)
80
+ ValidateIssuer = true , //是否验证Issuer
81
+ ValidateAudience = true , //是否验证Audience
82
+ ValidateLifetime = true , //是否验证失效时间
83
+ ValidateIssuerSigningKey = true , //是否验证SecurityKey
84
84
ValidAudience = AppSetting . Secret . Audience , //Audience
85
- ValidIssuer = AppSetting . Secret . Issuer , //Issuer,这两项和前面签发jwt的设置一致
85
+ ValidIssuer = AppSetting . Secret . Issuer , //Issuer,这两项和前面签发jwt的设置一致
86
86
IssuerSigningKey = new SymmetricSecurityKey ( Encoding . UTF8 . GetBytes ( AppSetting . Secret . JWT ) )
87
87
} ;
88
88
options . Events = new JwtBearerEvents ( )
@@ -93,16 +93,16 @@ public void ConfigureServices(IServiceCollection services)
93
93
context . Response . Clear ( ) ;
94
94
context . Response . ContentType = "application/json" ;
95
95
context . Response . StatusCode = 401 ;
96
- context . Response . WriteAsync ( new { message = "授权未通过" , status = false , code = 401 } . Serialize ( ) ) ;
96
+ context . Response . WriteAsync ( new { message = "授权未通过" , status = false , code = 401 } . Serialize ( ) ) ;
97
97
return Task . CompletedTask ;
98
98
}
99
99
} ;
100
100
} ) ;
101
- //必须appsettings.json中配置
101
+ //必须appsettings.json中配置
102
102
string corsUrls = Configuration [ "CorsUrls" ] ;
103
103
if ( string . IsNullOrEmpty ( corsUrls ) )
104
104
{
105
- throw new Exception ( "请配置跨请求的前端Url" ) ;
105
+ throw new Exception ( "请配置跨请求的前端Url" ) ;
106
106
}
107
107
services . AddCors ( options =>
108
108
{
@@ -118,20 +118,20 @@ public void ConfigureServices(IServiceCollection services)
118
118
services . AddControllers ( ) ;
119
119
services . AddSwaggerGen ( c =>
120
120
{
121
- //分为2份接口文档
122
- c . SwaggerDoc ( "v1" , new OpenApiInfo { Title = "VOL.Core后台Api" , Version = "v1" , Description = "这是对文档的描述。。" } ) ;
123
- c . SwaggerDoc ( "v2" , new OpenApiInfo { Title = "VOL.Core对外三方Api" , Version = "v2" , Description = "xxx接口文档" } ) ; //控制器里使用[ApiExplorerSettings(GroupName = "v2")]
124
- //启用中文注释功能
125
- var basePath = PlatformServices . Default . Application . ApplicationBasePath ;
126
- var xmlPath = Path . Combine ( basePath , "VOL.WebApi.xml" ) ;
127
- c . IncludeXmlComments ( xmlPath , true ) ; //显示控制器xml注释内容
128
- //添加过滤器 可自定义添加对控制器的注释描述
121
+ //分为2份接口文档
122
+ c . SwaggerDoc ( "v1" , new OpenApiInfo { Title = "VOL.Core后台Api" , Version = "v1" , Description = "这是对文档的描述。。" } ) ;
123
+ c . SwaggerDoc ( "v2" , new OpenApiInfo { Title = "VOL.Core对外三方Api" , Version = "v2" , Description = "xxx接口文档" } ) ; //控制器里使用[ApiExplorerSettings(GroupName = "v2")]
124
+ //启用中文注释功能
125
+ // var basePath = PlatformServices.Default.Application.ApplicationBasePath;
126
+ // var xmlPath = Path.Combine(basePath, "VOL.WebApi.xml");
127
+ // c.IncludeXmlComments(xmlPath, true);//显示控制器xml注释内容
128
+ //添加过滤器 可自定义添加对控制器的注释描述
129
129
//c.DocumentFilter<SwaggerDocTag>();
130
130
131
131
var security = new Dictionary < string , IEnumerable < string > > { { AppSetting . Secret . Issuer , new string [ ] { } } } ;
132
132
c . AddSecurityDefinition ( "Bearer" , new OpenApiSecurityScheme ( )
133
133
{
134
- Description = "JWT授权token前面需要加上字段Bearer与一个空格,如Bearer token" ,
134
+ Description = "JWT授权token前面需要加上字段Bearer与一个空格,如Bearer token" ,
135
135
Name = "Authorization" ,
136
136
In = ParameterLocation . Header ,
137
137
Type = SecuritySchemeType . ApiKey ,
@@ -186,7 +186,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
186
186
app . UseDefaultFiles ( ) ;
187
187
app . Use ( HttpRequestMiddleware . Context ) ;
188
188
189
- //2021.06.27增加创建默认upload文件夹
189
+ //2021.06.27增加创建默认upload文件夹
190
190
string _uploadPath = ( env . ContentRootPath + "/Upload" ) . ReplacePath ( ) ;
191
191
192
192
if ( ! Directory . Exists ( _uploadPath ) )
@@ -198,24 +198,24 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
198
198
{
199
199
FileProvider = new PhysicalFileProvider (
200
200
Path . Combine ( Directory . GetCurrentDirectory ( ) , @"Upload" ) ) ,
201
- //配置访问虚拟目录时文件夹别名
201
+ //配置访问虚拟目录时文件夹别名
202
202
RequestPath = "/Upload" ,
203
203
OnPrepareResponse = ( Microsoft . AspNetCore . StaticFiles . StaticFileResponseContext staticFile ) =>
204
204
{
205
- //可以在此处读取请求的信息进行权限认证
205
+ //可以在此处读取请求的信息进行权限认证
206
206
// staticFile.File
207
207
// staticFile.Context.Response.StatusCode;
208
208
}
209
209
} ) ;
210
- //配置HttpContext
210
+ //配置HttpContext
211
211
app . UseStaticHttpContext ( ) ;
212
212
213
213
app . UseSwagger ( ) ;
214
214
app . UseSwaggerUI ( c =>
215
215
{
216
- //2个下拉框选项 选择对应的文档
217
- c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "VOL.Core后台Api" ) ;
218
- c . SwaggerEndpoint ( "/swagger/v2/swagger.json" , "测试第三方Api" ) ;
216
+ //2个下拉框选项 选择对应的文档
217
+ c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "VOL.Core后台Api" ) ;
218
+ c . SwaggerEndpoint ( "/swagger/v2/swagger.json" , "测试第三方Api" ) ;
219
219
c . RoutePrefix = "" ;
220
220
} ) ;
221
221
app . UseRouting ( ) ;
@@ -225,7 +225,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
225
225
app . UseEndpoints ( endpoints =>
226
226
{
227
227
endpoints . MapControllers ( ) ;
228
- //配置SignalR
228
+ //配置SignalR
229
229
if ( AppSetting . UseSignalR )
230
230
{
231
231
string corsUrls = Configuration [ "CorsUrls" ] ;
@@ -242,22 +242,22 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
242
242
}
243
243
244
244
/// <summary>
245
- /// Swagger注释帮助类
245
+ /// Swagger注释帮助类
246
246
/// </summary>
247
247
public class SwaggerDocTag : IDocumentFilter
248
248
{
249
249
/// <summary>
250
- /// 添加附加注释
250
+ /// 添加附加注释
251
251
/// </summary>
252
252
/// <param name="swaggerDoc"></param>
253
253
/// <param name="context"></param>
254
254
public void Apply ( OpenApiDocument swaggerDoc , DocumentFilterContext context )
255
255
{
256
- //添加对应的控制器描述
256
+ //添加对应的控制器描述
257
257
swaggerDoc . Tags = new List < OpenApiTag >
258
258
{
259
- new OpenApiTag { Name = "Test" , Description = "这是描述" } ,
260
- //new OpenApiTag { Name = "你的控制器名字,不带Controller", Description = "控制器描述" },
259
+ new OpenApiTag { Name = "Test" , Description = "这是描述" } ,
260
+ //new OpenApiTag { Name = "你的控制器名字,不带Controller", Description = "控制器描述" },
261
261
} ;
262
262
}
263
263
}
0 commit comments