上一步我们创建好CoreApi
接下来在框架中加入 Swagger 并发布 到 IIS
(1)首先点击依赖项》管理Nuget包
(2)输入 Swashbuckle.aspnetCore 比如:
图中两个Swagger 插件需要我们安装 注意:我这里已经安装过显示的是 卸载
(3) 在框架中 添加Swagger 注解的帮助类 HttpHeaderOperation 下面是我完整的.CS文件
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Threading.Tasks;//添加引用
usingSwashbuckle.AspNetCore.Swagger;usingSwashbuckle.AspNetCore.SwaggerGen;usingMicrosoft.AspNetCore.Authorization;namespaceWebCoreApi
{public classHttpHeaderOperation : IOperationFilter
{///
///实现接口///
///
///
public voidApply(Operation operation, OperationFilterContext context)
{if (operation.Parameters == null)
{
operation.Parameters= new List();
}var actionAttrs =context.ApiDescription.ActionAttributes();var isAuthorized = actionAttrs.Any(a => a.GetType() == typeof(AuthorizeAttribute));if (isAuthorized == false) //提供action都没有权限特性标记,检查控制器有没有
{var controllerAttrs =context.ApiDescription.ControllerAttributes();
isAuthorized= controllerAttrs.Any(a => a.GetType() == typeof(AuthorizeAttribute));
}var isAllowAnonymous = actionAttrs.Any(a => a.GetType() &