aspnet zero的Swagger默认没有Authorize 按钮,这样测试起来很不方便,经过一番操作,终于成功解决了。
其实比较简单,只要在web.Host项目里的startup.cs里的代码添加一些代码就可以了:
原来的代码:
services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Title = "FlightProxyFee API", Version = "v1" }); options.DocInclusionPredicate((docName, description) => true); }
新增加代码:
services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Title = "FlightProxyFee API", Version = "v1" }); options.DocInclusionPredicate((docName, description) => true); //新增加代码 options.AddSecurityDefinition("Bearer", new ApiKeyScheme { Description = "JWT Authorization header using the Bearer scheme. Example: "Authorization: Bearer {token}"", Name = "Authorization", In = "header", Type = "apiKey" }); });