hello all,
how to get full name from Active Directory (AD) based on
windows user name (strUserID) in "web form". I got error message. any idea?
Code
Public Function GetUserInfo(ByVal UserID As String)
Dim RootDSE AsNew DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN AsString = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry AsNew DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
Dim ADSearchResult As System.DirectoryServices.SearchResult
ADSearch.Filter = ("(samAccountName=" & UserID & ")")
ADSearch.SearchScope = SearchScope.Subtree
Dim UserFound As SearchResult = ADSearch.FindOne()
If Not IsNothing(UserFound) Then
MsgBox(UserFound.GetDirectoryEntry().Properties.Item("name").Value)
End If
End Function
Error
An operations error occurred
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: An
operations error occurred
Source Error:
Line 62: Dim UserFound As SearchResult = ADSearch.FindOne()
how to get full name from Active Directory (AD) based on
windows user name (strUserID) in "web form". I got error message. any idea?
Code
Public Function GetUserInfo(ByVal UserID As String)
Dim RootDSE AsNew DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN AsString = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry AsNew DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
Dim ADSearchResult As System.DirectoryServices.SearchResult
ADSearch.Filter = ("(samAccountName=" & UserID & ")")
ADSearch.SearchScope = SearchScope.Subtree
Dim UserFound As SearchResult = ADSearch.FindOne()
If Not IsNothing(UserFound) Then
MsgBox(UserFound.GetDirectoryEntry().Properties.Item("name").Value)
End If
End Function
Error
An operations error occurred
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: An
operations error occurred
Source Error:
Line 62: Dim UserFound As SearchResult = ADSearch.FindOne()