asp.net-core – 如何在.NET Core 2.0中使用PrincipalContext
我在.NET Core 2.0中创建了一个Web应用程序,我想在命名空间System.DirectoryServices.AccountManagement中使用PrincipalContext.
我想再次验证用户的Active Directory,如下所示: private static ClaimsIdentity ValidateUser(string userName,string password) { var domain = GetDomainByLogin(userName); using (var pc = new PrincipalContext(ContextType.Domain,domain,null,ContextOptions.Negotiate)) { if (!pc.ValidateCredentials(userName,password)) return null; var user = UserPrincipal.FindByIdentity(pc,IdentityType.SamAccountName,userName); if (user == null) { throw new Exception(UserNotFound); } var id = new ClaimsIdentity(); id.AddClaim(new Claim(JwtClaimTypes.Subject,userName)); id.AddClaim(new Claim(JwtClaimTypes.Name,userName)); var groups = user.GetGroups(); var roles = groups.Select(x => new Claim(JwtClaimTypes.Role,x.Name)); id.AddClaims(roles); return id; } } 如何在.NET Core 2.0中使用PrincipalContext(System.DirectoryServices.AccountManagement)? 解决方法
可以获取.NET Core 2.0的System.DirectoryServices.AccountManagement的预览版本.
来自myget – https://dotnet.myget.org/feed/dotnet-core/package/nuget/System.DirectoryServices.AccountManagement 可通过此Feed获取Nuget包:https://dotnet.myget.org/F/dotnet-core/api/v3/index.json 关于这一点的扩展讨论在这里:https://github.com/dotnet/corefx/issues/2089 更新: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc-3 – 如何创建Quartz.NET的工作,需要使用autof
- 在ASP.NET或ASP.NET MVC中生成管理界面
- ASP.NET MVC路由的无限URL参数
- asp.net-mvc-3 – 由Enter按钮触发的MVC3输入按钮
- asp.net-mvc – ModelState.IsValid是假的 – 但是哪一个 –
- asp.net-mvc – 在ASP.NET MVC中的ReturnUrl
- ASP.Net中父/子UI设计的最佳实践?
- asp.net – 从SignalR中的所有组中删除连接
- 将ASP.Net Web.Config设置绑定到.ASPX文件?
- asp.net-mvc – ASP.NET MVC:使用EF实体作为模型?
- asp.net – 如何检测脚本管理器是否在页面上?
- asp-classic – 你用什么来编辑和开发经典ASP
- asp.net – ASP GridView在编辑模式下的所有行
- ASP.NET Identity会话cookie的安全性如何?
- asp.net-mvc – SQL CE 4.0还是SQL Express?果园
- asp.net-mvc-3 – 作为构建后事件的aspnet_compi
- asp.net api使用NPOI 导出xls
- 使用CQRS的ASP.NET MVC应用程序的良好读取模型是
- .net – 如何强制硬刷新(ctrl F5)?
- asp.net – IsPostBack,IsAsync和IsCallback有什