Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"A referral was returned from the server" exception when accessing AD from C#

Tags:

DirectoryEntry oDE = new DirectoryEntry("LDAP://DC=Test1,DC=Test2,DC=gov,DC=lk");  using (DirectorySearcher ds = new DirectorySearcher(oDE)) {     ds.PropertiesToLoad.Add("name");     ds.PropertiesToLoad.Add("userPrincipalName");      ds.Filter = "(&(objectClass=user))";      SearchResultCollection results = ds.FindAll();      foreach (SearchResult result in results)     {         Console.WriteLine("{0} - {1}",             result.Properties["name"][0].ToString(),             result.Properties["userPrincipalName"][0].ToString());     } } 

On the SearchResultCollection results = ds.FindAll(); line I get an exception:

A referral was returned from the server

Why do I get that exception and what does it mean?

like image 925
vml19 Avatar asked Aug 05 '11 09:08

vml19


1 Answers

Probably the path you supplied was not correct. Check that.

I would recomment the article Howto: (Almost) Everything In Active Directory via C# which really helped me in the past in dealing with AD.

like image 124
Fred Avatar answered Sep 21 '22 14:09

Fred