asp.net-web-api – 使用swashbuckle api文档的http basic auth
发布时间:2020-09-01 19:13:52 所属栏目:asp.Net 来源:互联网
导读:谁能知道如何将基本的auth与swashbuckle api的文档集成? 我看到swaggerconfig文件中有一个basicAuth函数: c.BasicAuth(basic).Description(Basic HTTP Authentication); 我做了什么: 取消注释前一行但没有改变! 有没有人知道我错过了什么? 谢谢! 这是我
谁能知道如何将基本的auth与swashbuckle api的文档集成? 我看到swaggerconfig文件中有一个basicAuth函数: c.BasicAuth("basic").Description("Basic HTTP Authentication"); 我做了什么: >取消注释前一行但没有改变! 有没有人知道我错过了什么? 谢谢! 解决方法这是我做httpbasic身份验证的方式:public class AddAuthorizationHeaderParameterOperationFilter: IOperationFilter { public void Apply(Operation operation,SchemaRegistry schemaRegistry,ApiDescription apiDescription) { var filterPipeline = apiDescription.ActionDescriptor.GetFilterPipeline(); var isAuthorized = filterPipeline .Select(filterInfo => filterInfo.Instance) .Any(filter => filter is IAuthorizationFilter); var allowAnonymous = apiDescription.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any(); if (isAuthorized && !allowAnonymous) { operation.parameters.Add(new Parameter { name = "Authorization",@in = "header",description = "access token",required = true,type = "string" }); } } } api的用户应写入字段值:basic [un:pw] .tobase64. 参考文献: (编辑:哈尔滨站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 未知的服务器标签’ajaxToolkit:CalendarExten
- asp.net-mvc – ELMAH和SQL Server 2008 R2?
- asp.net-mvc-3 – 如何在Razor视图引擎中注册程序集
- Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附
- asp.net-web-api – Web Api:找不到System.Net.Http版本2.
- asp.net-mvc – 使用没有ORM的ASP.NET MVC
- asp.net-mvc – 从Api控制器内生成绝对的url to action
- ASP.NET缓存的方法和最佳实践
- asp.net – 将ViewState移出页面?
- asp.net-mvc – mvc razor @helper可以返回非编码标签吗?
推荐文章
站长推荐
- asp.net-core – .NET Core SDK安装程序无法在Wi
- asp.net-core – 如何使用FluentValidation.AspN
- asp.net – 访问asp:从代码背后的内容
- asp.net – 查询字符串参数使我的应用程序面临风
- asp.net-mvc – 存储库与DAL中的服务模式:EF和D
- asp.net – Visual Studio – 为什么.ASPX文件比
- 什么OverrideAuthenticationAttribute是为什么?
- ASP.NET如何确定是否排队请求?
- asp.net – 哪里是.ASPXAUTH cookie
- .net – 可以为空的枚举类型的奇怪行为
热点阅读