C# 添加新用户active directory
我得到这个错误 “服务器不愿意处理此请求” 当我想在active directory中添加用户时 源代码:C# 添加新用户active directory,c#,active-directory,C#,Active Directory,我得到这个错误 “服务器不愿意处理此请求” 当我想在active directory中添加用户时 源代码: public static void SubmitUser(string OU, string username, string password, bool enabled, string givenName) { using (PrincipalContext ctx = GetPrincipalContext(OU)) {
public static void SubmitUser(string OU, string username, string password, bool enabled,
string givenName)
{
using (PrincipalContext ctx = GetPrincipalContext(OU))
{
UserPrincipalEx user = UserPrincipalEx.FindByIdentity(ctx, IdentityType.SamAccountName, username);
if (user == null)
{
user = new UserPrincipalEx(ctx);
user.SamAccountName = username;
user.SetPassword(password);
}
user.Enabled = enabled;
//if (!string.IsNullOrEmpty(username) && user.SamAccountName != username)
//{
// user.SamAccountName = username;
//}
if (!string.IsNullOrEmpty(givenName) && user.GivenName != givenName)
{
user.GivenName = givenName;
}
帐户是否有创建用户的权限?您是否尝试调用user.CommitChanges()?在哪一行出现错误?