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"
                });
            });

  

 

相关文章:

  • 2021-12-19
  • 2022-12-23
  • 2021-12-29
  • 2021-09-18
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2021-07-05
相关资源
相似解决方案