aspnet zero Swagger 不出现Authorize按钮的解决办法

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

  

 

posted @ 2018-03-15 09:48  飞翔的天空  阅读(2695)  评论(2编辑  收藏  举报