Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6541653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:07:51+00:00 2026-05-25T11:07:51+00:00

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);

  • 0
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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:07:51+00:00Added an answer on May 25, 2026 at 11:07 am

    This is the answer for the question.Reason for the cause is my LDAP string was wrong.

        try
        {
            string adServer = ConfigurationManager.AppSettings["Server"];
            string adDomain = ConfigurationManager.AppSettings["Domain"];
            string adUsername = ConfigurationManager.AppSettings["AdiminUsername"];
            string password = ConfigurationManager.AppSettings["Password"];
            string[] dc = adDomain.Split('.');
            string dcAdDomain = string.Empty;
    
            foreach (string item in dc)
            {
                if (dc[dc.Length - 1].Equals(item))
                    dcAdDomain = dcAdDomain + "DC=" + item;
                else
                    dcAdDomain = dcAdDomain + "DC=" + item + ",";
            }
    
            DirectoryEntry de = new DirectoryEntry("LDAP://" + adServer + "/CN=Users," + dcAdDomain, adUsername, password);
    
            DirectorySearcher ds = new DirectorySearcher(de);
    
            ds.SearchScope = SearchScope.Subtree;
    
            ds.Filter = "(&(objectClass=User)(sAMAccountName=" + username + "))";
    
            if (ds.FindOne() != null)
                return true;
        }
        catch (Exception ex)
        {
            ExLog(ex);
        }
        return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm missing something here: $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry $objSearcher.Filter =
DirectoryEntry testAD = new DirectoryEntry(); DirectorySearcher search = new DirectorySearcher(testAD); StringBuilder add = new
I'm using this query by C# in Active Directory: DirectoryEntry de = new DirectoryEntry(LDAP://
I can get the OU object like.... DirectoryEntry de = new DirectoryEntry( LDAP://domain.com, DOMAIN\\Administrator,
I'm trying to run a simple LDAP query using directory services in .Net. DirectoryEntry
I use this code: DirectoryEntry objEntry; DirectorySearcher objSearchEntry; SearchResultCollection objSearchResult; string strFilter = (&(objectCategory=User));
If I set the .NET DirectoryEntry.Path to something like: LDAP://CN=John Smith,OU=Group Name,DC=example,DC=com Everything works
string ouString = projectBox.Text.ToString(); string parentName = LDAP://OU=+ouString+,OU=Clients,OU=Clients,DC=domain,DC=net; DirectoryEntry parentEntry = new DirectoryEntry(parentName); DirectoryEntry
I'm new to accessing IIS 6.0 using C# code. I'm using DirectoryEntry to set
string path = LDAP://192.168.0.20/CN=users,DC=company,DC=ltm,DC=dom; DirectoryEntry dir = new DirectoryEntry(path, admin, pass, AuthenticationTypes.ServerBind); object value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.