locked
Querying Active Directory RRS feed

  • Question

  • User-331527780 posted

    This is my first experience attempting to connect to an LDAP with ASP.NET 2.0 in C#.  From all of my searching on the web it seems that the only way to connect to the LDAP is by using the built in membership.  Is this really the case???  What I need to do is to see if the user is in the LDAP, and then if they are I need to extract some data stored about them so that I can put it into a SQL Server database.  I kept seeing examples using System.DirectoryServices, but apparently that is now obsolete as far as I can tell.  Any help in this matter would be GREATLY  appreciated.

    Monday, November 5, 2007 11:51 AM

Answers

  • User-186742165 posted

    Hi

    The Active Directory hierarchy contains up to a variety of nodes. Each node represents an object, such as a network printer or a user in a domain. Those Active Directory nodes or objects can be associated with the DirectoryEntry component. You need to import the System.DirectoryServices namespace to access to Active Directory before using DirectoryEntry Object.

    ActiveDirectoryMemberShipProvider can also be used to access Active Directory. If you use .Net Reflector to check the implementation of the “ActiveDirectoryMembershipProvider” class, you can see the following code

    public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
    ...
       try
        {
            DirectoryEntryHolder holder = ActiveDirectoryConnectionHelper.GetDirectoryEntry(this.directoryInfo, this.directoryInfo.CreationContainerDN, true);
            DirectoryEntry containerEntry = null;
            DirectoryEntry userEntry = null;
            try
            {       ...  userEntry = containerEntry.Children.Add(this.GetEscapedRdn("CN=" + username), "user");
                    this.SetPasswordPortIfApplicable(userEntry);
                    userEntry.Invoke("SetPassword", new object[] { password });
                    ...

    So ActiveDirectoryMemberShipProvider also works based on the DirectoryServices. These functions provide a complete membership services for ASP.NET 2.0 enabled web applications.

    For more information, please view this link

    http://msdn.microsoft.com/en-us/library/system.directoryservices(vs.80).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 7, 2007 1:34 AM

All replies

  • User-186742165 posted

    Hi

    The Active Directory hierarchy contains up to a variety of nodes. Each node represents an object, such as a network printer or a user in a domain. Those Active Directory nodes or objects can be associated with the DirectoryEntry component. You need to import the System.DirectoryServices namespace to access to Active Directory before using DirectoryEntry Object.

    ActiveDirectoryMemberShipProvider can also be used to access Active Directory. If you use .Net Reflector to check the implementation of the “ActiveDirectoryMembershipProvider” class, you can see the following code

    public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
    ...
       try
        {
            DirectoryEntryHolder holder = ActiveDirectoryConnectionHelper.GetDirectoryEntry(this.directoryInfo, this.directoryInfo.CreationContainerDN, true);
            DirectoryEntry containerEntry = null;
            DirectoryEntry userEntry = null;
            try
            {       ...  userEntry = containerEntry.Children.Add(this.GetEscapedRdn("CN=" + username), "user");
                    this.SetPasswordPortIfApplicable(userEntry);
                    userEntry.Invoke("SetPassword", new object[] { password });
                    ...

    So ActiveDirectoryMemberShipProvider also works based on the DirectoryServices. These functions provide a complete membership services for ASP.NET 2.0 enabled web applications.

    For more information, please view this link

    http://msdn.microsoft.com/en-us/library/system.directoryservices(vs.80).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 7, 2007 1:34 AM
  • User1349710760 posted

    So, the System.DirectoryServices is not obsolete/depreciated?

     Thanks!

    Wednesday, November 7, 2007 7:20 AM