Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

getting user information from Active Directory

Last post 05-19-2008, 10:32 AM by joe. 1 replies.
Sort Posts: Previous Next
  •  05-16-2008, 10:05 PM 3586

    getting user information from Active Directory

    Hi,
    Develop a application using ASP.Net and C#. This application should synchronize the user repository from the source which is Active Directory .In future we have to do the same with LDAP or ERP system.
    Now I dont know where to start with..in all the articles i found in the web related to Active Directory..i have seen LDAP path..what is LDAP..?
     I have written some code below which is giving some error "com exception:This server is not operational".
    string principal = this.Context.User.Identity.Name;

    string filter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "person", principal);

    string domain = "DOMAIN"; 

    string[] properties = new string[] { "fullname" };

    DirectoryEntry adRoot = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.Secure); 

    DirectorySearcher searcher = new DirectorySearcher(adRoot); 

    searcher.SearchScope = SearchScope.Subtree; 

    searcher.ReferralChasing = ReferralChasingOption.All; 

    searcher.PropertiesToLoad.AddRange(properties); 

    searcher.Filter = filter;  

    SearchResult result = searcher.FindOne(); 

    DirectoryEntry directoryEntry = result.GetDirectoryEntry();

    but when running this it is giving some error
    "COM Exception:This server is not operational."
    I have installed my Pc with Windows XP.Now to how to set the path for LDAP..what should be the domain name..
    can anyone plzz help me regarding this..i am tired working with this.
    thanks.

  •  05-19-2008, 10:32 AM 3596 in reply to 3586

    Re: getting user information from Active Directory

    It looks like in this case the value you use for "domain" does not resolve to an AD domain.  What value do you have in there?

    You might consider instead getting the domain from the Identity.Name property since that will be in the format of "domain\user" if you are using Windows auth in IIS.  Also, you can only pass in the "user" part of "domain\user" in to your query against sAMAccountName since it does not contain the fully qualified NetBIOS domain name, just the unqualified part.

View as RSS news feed in XML