我在.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
更新:
最新的工作预览在这里:
https://dotnet.myget.org/feed/dotnet-core/package/nuget/System.DirectoryServices.AccountManagement/4.5.0-preview1-25726-06
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。