locked
Get active directory account info by credentials RRS feed

  • Question

  • User-1256393885 posted

    Hi

     How to get active directory account information by user credentials.

    The code i have written is giving the error : DirectoryServicesCOMException was handled by user code.

    protected void Page_Load(object sender, EventArgs e)

    {

    string UserName = this.Context.User.Identity.Name;

    DirectoryEntry NodeConnection = createDirectoryEntry();

    DirectorySearcher search = new DirectorySearcher(NodeConnection);

    search.Filter = "(cn=" + UserName + ")";

    SearchResult result = search.FindOne();

    if (result!=null)

    {

    ResultPropertyCollection fields = result.Properties;foreach (string ObjField in fields.PropertyNames)

    {

    foreach (Object myCollection in fields[ObjField])

    {

    Response.Write(
    String.Format("{0,-20} : {1}", ObjField, myCollection.ToString()));

    }

    }

    }

    }

    DirectoryEntry createDirectoryEntry()

    {

    // create and return new LDAP connection with desired settings

    DirectoryEntry ldapConnection = new DirectoryEntry("rizzo.leeds-art.ac.uk");

    ldapConnection.Path = "LDAP://OU=staffusers,DC=leeds-art,DC=ac,DC=uk";

    ldapConnection.AuthenticationType = AuthenticationTypes.Secure;

    return ldapConnection;

    }

     

     

    Thanks

    -atul

    Wednesday, October 22, 2008 6:49 AM

All replies