Sign in | Join
Last post 05-13-2009 12:41 PM by Vimpyboy. 1 replies.
Sort Posts: Oldest to newest Newest to oldest
Having an issue migrating from Visual Studio 2003 to 2005 and using asp.net 2.0 to validate local users. Code was the same as before and was working correctly except now I get an exception on the line results = mySearcher.FindAll(). Just wondering if LDAP is changed and if the below code is incorrect, searched various places and cannot find a solution yet. Any help appreciated.
Public Function GetUserFullName(ByVal username As String) As String Dim entry As New DirectoryEntry("LDAP://NETADDRESS") Dim mySearcher As New DirectorySearcher(entry) 'Dim result As SearchResult mySearcher.Filter = ("(&(objectClass=user)(SAMAccountName=" & username & "))") Dim results As SearchResultCollection results = mySearcher.FindAll() Select Case results.Count Case 0 Return "False" Case 1 Dim Name() As String = Split(results(0).GetDirectoryEntry().Name, "=") Return Name(1) Case Is > 1 'Return "Multiple" Dim Name() As String = Split(results(0).GetDirectoryEntry().Name, "=") Return Name(1) End Select Return Nothing End Function
You need to send your credentials to the DirectoryEntry before searching.
entry.Username = "domain\username"; entry.Password = "password";