2015-01-16 45 views
0

我有一個方法,將特定的用戶搜索到ADAM。如何搜索單用戶從LADP:

'set up the LDAP entry object 
     objEntry = New DirectoryEntry("LDAP://" & m_strLDAPServer & ":" & m_strLDAPPort & "/" & m_strLDAPEntry) 
is the default but it must be set explicitly so that the props array can be passed in 
     objSearcher = New DirectorySearcher(objChild, "(objectClass=*)", strProps) 
     objSearcher.SearchScope = SearchScope.Base 

objSearcher = New DirectorySearcher(objChild, "(objectClass=*)", strProps) 
     objSearcher.SearchScope = SearchScope.Base 
     'carry out the search 
     Try 
      objResult = objSearcher.FindOne() 
     Catch 
      objResult = Nothing 
     End Try 

我想要得到的結果,從ADAM SQL:像'%strUserName中%',但我發現的唯一方法FindOne(),只有搜索完整的字符串 「strUserName中」,但它不執行SQL Like操作。 任何想法如何像SQL LIKE一樣進行搜索?

回答

0

其正常工作:

eobjEntry = New DirectoryEntry("LDAP://" & m_strLDAPServer & ":" & m_strLDAPPort & "/" & "cn=" & txtUserName & "," & m_strLDAPEntry) 
    'set the user name and password, if necessary 

    Dim search As New DirectorySearcher() 

「這裏搜索& txtUserName &工作SQL同樣的操作, objSearcher =新的DirectorySearcher(objEntry 「(CN =」 & txtUserName & 「)」) objSearcher.SearchScope = SearchScope.Base和SearchScope.OneLevel Dim results As SearchResult = search.FindOne()

+0

其工作原理類似於SQL'LIKE'操作。 –