The following code fails on the commented line the error message is Unknown error (0x80005000) Stack Trace ... [COMException (0x80005000): Unknown error (0x80005000)] System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +514 System.DirectoryServices.DirectoryEntry.Bind()
+10 System.DirectoryServices.DirectoryEntry.get_AdsObject() +10 System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) +199 System.DirectoryServices.DirectorySearcher.FindAll() +10 app1.myldap.Page_Load(Object sender, EventArgs e) in C:\Documents
and Settings\yquazi\VSWebCache\xfiles\app1\myldap.aspx.vb:33 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Page.ProcessRequestMain() +731 Dim objSearch As New DirectorySearcher objSearch.SearchRoot =
New DirectoryEntry("LDAP://myldap/ou=People, dc=something, dc=something") objSearch.Filter = "uid=*" objSearch.SearchScope = SearchScope.Subtree objSearch.PropertiesToLoad.Add("uid") Dim colQueryResults As SearchResultCollection 'colQueryResults = objSearch.FindAll()
Yaheya Quazi
Director, Admin. Comp. & Systems
University of California, Merced
If you are running this from ASP.NET, then the ASPNET user is likely running the code. This user is unknown to the Active Directory. You will need to bind with alternate credentials. Try specifying a .Username and .Password on the DirectoryEntry that you pass
to the DirectorySearcher. Use a valid domain user and password.
Hi as you can tell I am very new to LDAP. By the way, I am not using AD it is plain LDAP. How do I add username to Directoryentry? Do I add after these two lines? Dim objSearch As New DirectorySearcher objSearch.SearchRoot = New DirectoryEntry("LDAP://sss/ou=People,
dc=sss, dc=ddd") How ??
Yaheya Quazi
Director, Admin. Comp. & Systems
University of California, Merced
When you create the DirectoryEntry to pass to your DirectorySearcher, you need to add the username and password using the .Username and .Password properties or in-line with your code. Try this:
objSearch.SearchRoot = New DirectoryEntry("LDAP://sss/ou=People, dc=sss, dc=ddd", "DOMAIN\User", "password")
Alternatively, you need to split up the creation of the DirectoryEntry and assignment to the DirectorySearcher. This would work as well:
Dim entry as New DirectoryEntry("LDAP://sss/ou=People, dc=sss, dc=ddd", "DOMAIN\User", "password")
'This is where .Username and .Password can be found
'entry.Username = "DOMAIN\User"
'entry.Password = "password"
Dim searcher as new DirectorySearcher(entry)
ok I progressed a little but am getting the same error message...here is my code Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Dim objSearch As New DirectorySearcher Dim objsearch As New DirectoryEntry("ldap://ldap.somethign.edu/ou=people,
dc=blabla, dc=edu") objsearch.Username = "joe" objsearch.Password = "haha" Dim searcher As New DirectorySearcher(objsearch) searcher.Filter = "uid=*" searcher.SearchScope = SearchScope.Subtree searcher.PropertiesToLoad.Add("uid") Dim mystring As String = searcher.findone.tostring()
All I want to do is print the uid of the authenticated person in this case joe. Note both the username and password are valid. The line it is failing is this line Dim mystring As String = searcher.findone.tostring() This is absolutely killing me!
Yaheya Quazi
Director, Admin. Comp. & Systems
University of California, Merced
I will try to clear up your confusion, if I can. The username and password is only used to provide credentials to the Directory allowing you to search. They have nothing to do with what you will search for. It is like logging on to the Directory, and then doing
whatever you want with the permissions you log on with. If you don't provide these credentials, it will try to logon to the Directory using ASPNET user, which doesn't exist in directory and causes the error you see. What is the brand of LDAP directory you
are using? If it is AD, then "DOMAIN\joe" format (to .Username), or you might run into issues. If it is other, then you probably need the DN of Joe (e.g. CN=Joe,CN=Users,O=company.com) as the username. Next, your search filter will not work. It is invalid
to begin with since it requires "()" around any filter. Try "(uid=Joe)" as a search filter (note the domain portion is missing this time!). Finally, .FindOne() returns a SearchResult, so trying to use ToString() does not make sense. You need to access the
properties you loaded with .PropertiesToLoad.Add() method. It should look more like this instead:
Dim sr as SearchResult = searcher.FindOne()
Dim mystring as String = sr.Properties["uid"][0].ToString()
hi when I run the following code it run (note the commented line) and it produces no error message...but when I uncomment the two lines I get an unspecified error...If I am not doing things right then how come I don't get error when I run the code without the
commented line?? This is abosolutely making me crazy. Why can't the world be more one platform - WINDOWS!!!! Dim objsearch As New DirectoryEntry("ldap://ldap.mydomain.edu/") objsearch.Username = "myuser" objsearch.Password = "myuser" Dim searcher As New DirectorySearcher(objsearch)
searcher.Filter = "uid=*" searcher.SearchScope = SearchScope.Subtree searcher.PropertiesToLoad.Add("cn") 'Dim sr As SearchResult = searcher.FindOne() 'Dim mystring As String = sr.Properties("cn")(0).ToString()
Yaheya Quazi
Director, Admin. Comp. & Systems
University of California, Merced
Since you are using Sun LDAP, you need to update the .Username to be in DN format. Don't forget to also fix your search filter. Check back to my last post to see what I mean. The reason you don't get any error when you comment those lines out is that no binding
to the directory is done until the call to .FindOne().
yaheya
Participant
1635 Points
340 Posts
What am I doing wrong??
Aug 19, 2003 09:32 PM|LINK
Director, Admin. Comp. & Systems
University of California, Merced
dunnry
Star
9098 Points
1806 Posts
Re: What am I doing wrong??
Aug 19, 2003 11:06 PM|LINK
Weblog
The Book
LDAP Programming Help
yaheya
Participant
1635 Points
340 Posts
Re: What am I doing wrong??
Aug 19, 2003 11:59 PM|LINK
Director, Admin. Comp. & Systems
University of California, Merced
dunnry
Star
9098 Points
1806 Posts
Re: What am I doing wrong??
Aug 20, 2003 12:39 PM|LINK
objSearch.SearchRoot = New DirectoryEntry("LDAP://sss/ou=People, dc=sss, dc=ddd", "DOMAIN\User", "password")Alternatively, you need to split up the creation of the DirectoryEntry and assignment to the DirectorySearcher. This would work as well:Dim entry as New DirectoryEntry("LDAP://sss/ou=People, dc=sss, dc=ddd", "DOMAIN\User", "password") 'This is where .Username and .Password can be found 'entry.Username = "DOMAIN\User" 'entry.Password = "password" Dim searcher as new DirectorySearcher(entry)This accomplishes same thingWeblog
The Book
LDAP Programming Help
yaheya
Participant
1635 Points
340 Posts
Re: What am I doing wrong??
Aug 20, 2003 03:52 PM|LINK
Director, Admin. Comp. & Systems
University of California, Merced
dunnry
Star
9098 Points
1806 Posts
Re: What am I doing wrong??
Aug 20, 2003 04:50 PM|LINK
Weblog
The Book
LDAP Programming Help
yaheya
Participant
1635 Points
340 Posts
Re: What am I doing wrong??
Aug 20, 2003 07:07 PM|LINK
Director, Admin. Comp. & Systems
University of California, Merced
yaheya
Participant
1635 Points
340 Posts
Re: What am I doing wrong??
Aug 20, 2003 07:21 PM|LINK
Director, Admin. Comp. & Systems
University of California, Merced
dunnry
Star
9098 Points
1806 Posts
Re: What am I doing wrong??
Aug 20, 2003 07:33 PM|LINK
Weblog
The Book
LDAP Programming Help
yaheya
Participant
1635 Points
340 Posts
Re: What am I doing wrong??
Aug 20, 2003 07:44 PM|LINK
Director, Admin. Comp. & Systems
University of California, Merced