Directory Programming .NET

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

Accessing User Data in Active Directory

Last post 03-19-2010, 8:57 AM by joe. 7 replies.
Sort Posts: Previous Next
  •  03-16-2010, 3:11 PM 7964

    Accessing User Data in Active Directory

    Hello,

    I'm hoping that someone can assist me as I feel like I've been spinning my wheels trying to figure this out.

    I am trying to get a specific users AD attributes (example name) but I don't get any values except for the odd public information attribute. The following is my code...

    Dim strPath 'path to the directory server
    Dim objMyObject 'root object of the directory
    Dim strUsername
    Dim strPassword
    Dim ObjNamespaceLDAP

    Const ADS_SECURE_AUTHENTICATION = 1
    Const ADS_USE_ENCRYPTION = 2

    strPath = "LDAP://dmnet.net"
    strUsername = pass_user
    strPassword = pass_password

    objNamespaceLDAP = GetObject("LDAP:")

    objMyObject = objNamespaceLDAP.OpenDSObject(strPath,strUsername,strPassword,0)

    thisname = objMyObject.Get("Name")

    The "Name" attribute retuns the Doman Name for me but there are not too many other attributes I can view. I would like to get such vales as displayName.

    Any assistance would be greatly appreciated!

    Thanks,
    Joanne
  •  03-17-2010, 8:58 AM 7967 in reply to 7964

    Re: Accessing User Data in Active Directory

    I don't usually handle questions on vbscript in this forum but I'll try.

    The main issue here is that you are reading the domain root object, not a specific user. If you want to read values on a user, you must either create an object that points to them by their specific path or use a search to find the user and read the values from the search results.

    Also, don't use "0" for your auth flags value. That does simple bind and passes the credentials in plain text on the network. Not good. Use 1.

  •  03-18-2010, 9:33 AM 7980 in reply to 7967

    Re: Accessing User Data in Active Directory

    Thanks for the help Joe. I am very new to AD and trying to access it through programming! I have a lot to learn.

    I have specified a specific user (hopefully correctly) but I get an error

    Cannot create ActiveX component.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    I am not sure what causes this error... any ideas or can you point me in any direction?

    Thanks,
    Joanne
  •  03-18-2010, 1:00 PM 7983 in reply to 7980

    Re: Accessing User Data in Active Directory

    Hi Joanne,

    If you got an exception, that would seem to indicate that you are using .NET/ASP.NET to build your web app. In that case, you should not be programming with the legacy COM objects used in classic ASP for this. You should be using System.DirectoryServices or System.DirectoryServices.AccountManagement.

    Ryan and I wrote a whole book about this which is what the website was originally created to support. I don't want to say you have to buy it, but it might be really helpful to you and save you a lot of time.

    However, it isn't really for novice .NET developers either. If you don't have any .NET skills or know ASP.NET, you might want to try to build up some of the basics first. Otherwise, you'll have a hard time. Such is the thing with learning any kind of new broad technology.

    Best of luck!

  •  03-18-2010, 2:14 PM 7986 in reply to 7983

    Re: Accessing User Data in Active Directory

    Hi Joe,

    I was actually looking at your book... just a question... does it mainly reference C? I normally do my programming using VB. I am fairly new to ASP.NET as well so I guess I should start with increasing my knowledge of .net first.

    Thanks,
    Joanne
  •  03-18-2010, 9:29 PM 7988 in reply to 7986

    Re: Accessing User Data in Active Directory

    All the samples in the book were translated by me from C# to VB.NET and posted on the book's website. The text in the book is fairly neutral. They would not let us publish the book in VB.NET or release a separate VB version. :)

    There is actually not that much important difference between C# and VB.NET, especially in terms of what we are trying to show. You have ; and {} vs. "End xxx" blocks and such but it is all pretty easy to read.

    However, it is probably a good idea to get some ASP.NET basics first.

  •  03-19-2010, 8:13 AM 7990 in reply to 7988

    Re: Accessing User Data in Active Directory

    Thanks Joe, I appreciate your help! I think I'll work on my asp.net but will be looking to purchase your book as well. I've been going in circles with this stuff and some books would be a good idea to reference!
  •  03-19-2010, 8:57 AM 7991 in reply to 7990

    Re: Accessing User Data in Active Directory

    In the meantime, feel free to post specific questions. I'd suggest sticking with SDS.AccountManagement if you can, although if you just need to do some simple searches, using the DirectorySearcher might be best.

    Most problems in ASP.NET applications can be traced back to executing under a different security context than you would running an app on the desktop and having assumptions about how connectivity to the directory break because of it.

View as RSS news feed in XML