none
Error Creating user in Active Directory using asp.net RRS feed

  • Question

  • Hi,

    I am trying to create new user in active directory but  it is giving error :

    The server is not operational.

    my code is :

     string groupDn = "IP address";
            try
            {

                DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + groupDn,"Administrator","password");
                DirectoryEntry newUser = dirEntry.Children.Add("CN=" + userName, "user");
                   
                    //.Children.Add("CN=" + userName, "user");
                newUser.Properties["samAccountName"].Value = userName;
                newUser.Properties["userprincipalname"].Value = userName + "@parallelminds.com";

                newUser.Properties["givenname"].Value = fName;
                newUser.Properties["sn"].Value = lName;

                newUser.Properties["displayname"].Value = fName + " " + lName;
                newUser.CommitChanges();

                newUser.Invoke("SetPassword", new object[] { userPassword });
                newUser.CommitChanges();
               
                dirEntry.Close();
                newUser.Close();

               
         
                Response.Write("User Added");
            }
            catch (System.DirectoryServices.DirectoryServicesCOMException E)
            {
                Response.Write( E.Message.ToString());

            }

     

    can anybody tell me what is wrong with this ?
    Tuesday, January 31, 2012 6:53 AM