我对 VB.net 很陌生。我可以使用 USING 语句来调用目录条目和搜索器,如下所示。
Using entry As DirectoryEntry = New DirectoryEntry(String.Format("LDAP://xxx.com.my"))
entry.AuthenticationType = AuthenticationTypes.Delegation
entry.Username = username
entry.Password = password
Using searcher As New DirectorySearcher(entry)
searcher.SearchScope = SearchScope.OneLevel
Try
Dim results As SearchResult = searcher.FindOne
success = Not (results Is Nothing)
Catch ex As Exception
success = False
WriteToFile("ValidateADLogin error : " & ex.Message)
End Try
End Using
End Using