从Active Directory获取用户
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从Active Directory获取用户相关的知识,希望对你有一定的参考价值。
string sAMAccountName = "<login name>"; string filter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "person", sAMAccountName); //you must provide a username and password to authenticate (this is not the username and password of the person you're looking for): searcher.SearchScope = SearchScope.Subtree; searcher.ReferralChasing = ReferralChasingOption.All; searcher.PropertiesToLoad.AddRange(properties); searcher.Filter = filter; SearchResult result = searcher.FindOne(); DirectoryEntry de = result.GetDirectoryEntry(); //you can now get the properties of the directory entry this way: string property = de.Properties["<property name>"].Value.ToString(); /*some examples of property names: co (country) c (country abbreviation) countryCode givenName (first name) title mobile sAMAccountName sn (last name) st (state) street streetAddress telephoneNumber postalCode */
以上是关于从Active Directory获取用户的主要内容,如果未能解决你的问题,请参考以下文章
LDAP:如何从 Active Directory 中获取所有用户和组
给定 UserPrincipal 对象,如何从 Active Directory 中获取“公司”和“部门”?
我可以将 Azure Active Directory 身份验证连接到现有项目吗?