[英]Active Directory Search to get users domain
I am trying to query Active directory for a user to get a list of details: 1. First/Last Name 2. Email 3. UserName 4. Domain 我正在尝试查询Active Directory中的用户以获取详细信息列表:1.名字/姓氏2.电子邮件3. UserName 4.域
I am able to get all except for the domain name. 我可以获取除域名之外的所有内容。 Here is my code: 这是我的代码:
Dim oroot As DirectoryEntry = New DirectoryEntry("GC://ldap.someCompany.com")
Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
Dim result As SearchResult
osearcher.Filter = String.Format("(&(SAMAccountName={0}))", "myUsername")
osearcher.PropertiesToLoad.Add("cn")
osearcher.PropertiesToLoad.Add("SAMAccountName") 'Users login name
osearcher.PropertiesToLoad.Add("givenName") 'Users first name
osearcher.PropertiesToLoad.Add("sn") 'Users sur name
osearcher.PropertiesToLoad.Add("mail") 'Email address
result = osearcher.FindOne
Try
myUser.UserID = result.Properties("cn").Item(0)
myUser.Domain = ""
myUser.EmailAddress = result.Properties("mail").Item(0)
myUser.FirstName = result.Properties("givenName").Item(0)
myUser.LastName = result.Properties("sn").Item(0)
myUser.Domain = result.Properties("displayName").Item(0)
Catch ex As Exception
Return Nothing
End Try
This returns this string: GC://ldap.someCompany.com/CN=FirstName M LastName,OU=Employees,OU=Domain Users,DC=val1,DC=val2,DC=com 这将返回以下字符串:GC://ldap.someCompany.com/CN=First Name M LastName,OU = Employees,OU = Domain Users,DC = val1,DC = val2,DC = com
So, I have two questions. 所以,我有两个问题。 First, how do I get the domain name of the user? 首先,如何获取用户的域名? It appears to be in DC= (where I have val1) Second, is there anyway to speed this search up? 它似乎在DC =中(我有val1)其次,是否有加快搜索的速度? Right now, it takes about 10 seconds to run the query. 现在,运行查询大约需要10秒钟。
I am using .net 4.0 and Visual Studio 2010 Thanks for any help 我正在使用.net 4.0和Visual Studio 2010感谢您的帮助
jason 杰森
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.