By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,687 Members | 1,509 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,687 IT Pros & Developers. It's quick & easy.

How to search in Active Direcoty

P: n/a
Hi there,
I am working on a web application in ASP.NET
My web server and AD machine are in the same domain but
located on diffrent phisical machine, I am not able to
search user's info by the following code if I pass only
path as parameter to DirectoyEntry class. The same code is
working if I pass all the three parameter as path,userId
and password. but I have to use windows authenticatoin and
can't get password from Windows
authenticatoin Popup box.....

I think I should be able to search in AD by only having
complete LDAP path and Username. I copy the complete code
here...I get System.Runtime.InteropServices.COMException
error on following line
Dim obj As Object = entry.NativeObject

Any help sincerelly appriciated...


Private path As String
Private filterAttribute As String
Public fullname As String
Public groupName As String
Public email As String

Public Sub GetUserDetails(ByVal domain As String, ByVal
username As String) ', ByVal pwd As String)
Dim domainAndUsername As [String] = domain & "\" &
Dim entry As New DirectoryEntry(path) ',
domainAndUsername, pwd)

'Bind to the native AdsObject to force
Dim obj As Object = entry.NativeObject

Dim search As New DirectorySearcher(entry)

search.Filter = "(SAMAccountName=" & username
& ")"
Dim result As SearchResult = search.FindOne()

'Update the new path to the user in the
path = result.Path
filterAttribute = CType(result.Properties("cn")
(0), String)
fullname = CType(result.Properties("cn")(0),
Dim resultemail As SearchResult =
email = CType(resultemail.Properties("mail")
(0), String)

Dim resultgp As SearchResult = search.FindOne()
groupName = CType(resultgp.Properties
("MemberOf")(0), String)

Catch ex As Exception
Throw New Exception("Error obtaining user
details. " + ex.Message)
End Try

End Sub 'GetUserDetails
Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.