Link to home
Start Free TrialLog in
Avatar of Boon Chye Phang
Boon Chye Phang

asked on

Received "The server cannot handle directory requests" exception message when trying to create Active Directory user account

When trying to create Active Directory user account using .Net code, received an exception that says:
The server cannot handle directory requests.

Open in new window

User generated image
Here is the source code:
User generated image
The solution online (https://stackoverflow.com/questions/3694919/nets-directory-services-throws-a-strange-exception) does not seems to be applicable because the IIS website is accessible from network, and used to be able to create user account.

Also tried adding port number (server:636) but it cannot reach the server.

Need help to identify what is the issue and to solve this.
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

That look like you doing generic LDA, not AD
Try using System.DirectoryServices.AccountManagement
Avatar of Boon Chye Phang
Boon Chye Phang

ASKER

Hi Shaun,

Is there an example of using System.DirectoryServices.AccountManagement?
using(var pc = new PrincipalContext(ContextType.Domain))
{
  using(var up = new UserPrincipal(pc))
  {
    up.SamAccountName = username;
    up.EmailAddress = email;
    up.SetPassword(password);
    up.Enabled = true;
    up.ExpirePasswordNow();
    up.Save();
  }
}

Open in new window

https://stackoverflow.com/questions/2305857/creating-active-directory-user-with-password-in-c-sharp?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
ASKER CERTIFIED SOLUTION
Avatar of Boon Chye Phang
Boon Chye Phang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It may have different scenarios having such message, but my case is due to password does not fit the AD server specified requirement