Skip to content

Commit 38a067d

Browse files
Merge branch 'master' of https://github.com/cq-panda/Vue.NetCore
2 parents 71e74e0 + 09c5523 commit 38a067d

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

Vue.Net/VOL.WebApi/Startup.cs

+32-32
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Startup(IConfiguration configuration)
4646
// This method gets called by the runtime. Use this method to add services to the container.
4747
public void ConfigureServices(IServiceCollection services)
4848
{
49-
//初始化模型验证配置
49+
//初始化模型验证配置
5050
services.UseMethodsModelParameters().UseMethodsGeneralParameters();
5151
services.AddSingleton<IObjectModelValidator>(new NullObjectModelValidator());
5252
Services = services;
@@ -76,13 +76,13 @@ public void ConfigureServices(IServiceCollection services)
7676
{
7777
options.TokenValidationParameters = new TokenValidationParameters
7878
{
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
8484
ValidAudience = AppSetting.Secret.Audience,//Audience
85-
ValidIssuer = AppSetting.Secret.Issuer,//Issuer,这两项和前面签发jwt的设置一致
85+
ValidIssuer = AppSetting.Secret.Issuer,//Issuer,这两项和前面签发jwt的设置一致
8686
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(AppSetting.Secret.JWT))
8787
};
8888
options.Events = new JwtBearerEvents()
@@ -93,16 +93,16 @@ public void ConfigureServices(IServiceCollection services)
9393
context.Response.Clear();
9494
context.Response.ContentType = "application/json";
9595
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());
9797
return Task.CompletedTask;
9898
}
9999
};
100100
});
101-
//必须appsettings.json中配置
101+
//必须appsettings.json中配置
102102
string corsUrls = Configuration["CorsUrls"];
103103
if (string.IsNullOrEmpty(corsUrls))
104104
{
105-
throw new Exception("请配置跨请求的前端Url");
105+
throw new Exception("请配置跨请求的前端Url");
106106
}
107107
services.AddCors(options =>
108108
{
@@ -118,20 +118,20 @@ public void ConfigureServices(IServiceCollection services)
118118
services.AddControllers();
119119
services.AddSwaggerGen(c =>
120120
{
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+
//添加过滤器 可自定义添加对控制器的注释描述
129129
//c.DocumentFilter<SwaggerDocTag>();
130130

131131
var security = new Dictionary<string, IEnumerable<string>> { { AppSetting.Secret.Issuer, new string[] { } } };
132132
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
133133
{
134-
Description = "JWT授权token前面需要加上字段Bearer与一个空格,如Bearer token",
134+
Description = "JWT授权token前面需要加上字段Bearer与一个空格,如Bearer token",
135135
Name = "Authorization",
136136
In = ParameterLocation.Header,
137137
Type = SecuritySchemeType.ApiKey,
@@ -186,7 +186,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
186186
app.UseDefaultFiles();
187187
app.Use(HttpRequestMiddleware.Context);
188188

189-
//2021.06.27增加创建默认upload文件夹
189+
//2021.06.27增加创建默认upload文件夹
190190
string _uploadPath = (env.ContentRootPath + "/Upload").ReplacePath();
191191

192192
if (!Directory.Exists(_uploadPath))
@@ -198,24 +198,24 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
198198
{
199199
FileProvider = new PhysicalFileProvider(
200200
Path.Combine(Directory.GetCurrentDirectory(), @"Upload")),
201-
//配置访问虚拟目录时文件夹别名
201+
//配置访问虚拟目录时文件夹别名
202202
RequestPath = "/Upload",
203203
OnPrepareResponse = (Microsoft.AspNetCore.StaticFiles.StaticFileResponseContext staticFile) =>
204204
{
205-
//可以在此处读取请求的信息进行权限认证
205+
//可以在此处读取请求的信息进行权限认证
206206
// staticFile.File
207207
// staticFile.Context.Response.StatusCode;
208208
}
209209
});
210-
//配置HttpContext
210+
//配置HttpContext
211211
app.UseStaticHttpContext();
212212

213213
app.UseSwagger();
214214
app.UseSwaggerUI(c =>
215215
{
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");
219219
c.RoutePrefix = "";
220220
});
221221
app.UseRouting();
@@ -225,7 +225,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
225225
app.UseEndpoints(endpoints =>
226226
{
227227
endpoints.MapControllers();
228-
//配置SignalR
228+
//配置SignalR
229229
if (AppSetting.UseSignalR)
230230
{
231231
string corsUrls = Configuration["CorsUrls"];
@@ -242,22 +242,22 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
242242
}
243243

244244
/// <summary>
245-
/// Swagger注释帮助类
245+
/// Swagger注释帮助类
246246
/// </summary>
247247
public class SwaggerDocTag : IDocumentFilter
248248
{
249249
/// <summary>
250-
/// 添加附加注释
250+
/// 添加附加注释
251251
/// </summary>
252252
/// <param name="swaggerDoc"></param>
253253
/// <param name="context"></param>
254254
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
255255
{
256-
//添加对应的控制器描述
256+
//添加对应的控制器描述
257257
swaggerDoc.Tags = new List<OpenApiTag>
258258
{
259-
new OpenApiTag { Name = "Test", Description = "这是描述" },
260-
//new OpenApiTag { Name = "你的控制器名字,不带Controller", Description = "控制器描述" },
259+
new OpenApiTag { Name = "Test", Description = "这是描述" },
260+
//new OpenApiTag { Name = "你的控制器名字,不带Controller", Description = "控制器描述" },
261261
};
262262
}
263263
}

0 commit comments

Comments
 (0)