当前位置: 首页 > 编程语言 > C#

我可以从WindowsPrincipal获取ActiveDirectory属性吗?分享

时间:2023-04-10 22:25:32 C#

我可以从WindowsPrincipal获取ActiveDirectory属性吗?我想获取当前登录用户的员工ID。这在某些.Net类中是否很容易获得,或者我是否需要进行某种LDAP查询?欢迎任何提示更简单-使用新的.NET3.5System.DirectoryServices.AccountManagement功能。有关详细信息,请参阅MSDN文章ManagingDirectorySecurityPrincipalsinthe.NETFramework3.5。PrincipalContextctx=newPrincipalContext(ContextType.Domain."YOURDOMAIN");UserPrincipaluser=UserPrincipal.FindByIdentity(ctx,loginName);如果(用户!=null){stringempID=user.EmployeeId;}新的强类型主体类使使用AD变得轻而易举。使用AD查询-很简单:以上是C#学习教程:CanIgetActiveDirectoryattributesfromWindowsPrincipal?如果分享的内容对你有用,需要了解更多C#学习教程,希望大家多多关注——DirectorySearcherds=newDirectorySearcher();ds.PropertiesToLoad.Add("员工ID");ds.Filter=String.Format("(&(objectCategory=person)(sAMAccountName={0}))",loginName);结果=ds.FindOne();if(result!=null){personnelNumber=result.Properties["employeeID"][0].ToString();}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: