使用.NET在sAMAccountName中创建具有超过20个字符的用户时出错

Car*_*mpo 9 .net c# vb.net active-directory

我正在尝试以编程方式创建一个新的Active Directory用户,使用大于20个字符的值设置sAMAccountName属性.

当我调用DirectoryEntry.CommitChanges()时,我收到错误:

00000523:SysErr:DSID-031A0FB6,问题22(参数无效),数据0

如果我尝试创建一个新用户设置sAMAccountName小于20个字符,一切正常.

在有人说sAMAccountName的限制为20个字符之前,我想指出,如果我尝试使用Windows工具"Active Directory用户和计算机"创建具有超过20个字符的sAMAccountName的同一用户,一切正常.我可以使用LDP工具在AD中看到新条目,并且条目具有超过20个字符的sAMAccountName.

为什么我不能使用.NET以编程方式创建用户?

以下是我正在使用的代码:

Using objDirEnt As DirectoryEntry = New DirectoryEntry("LDAP://my.domain.com/cn=Users,dc=my,dc=domain,dc=com", "username", "Password", AuthenticationTypes.Secure Or AuthenticationTypes.Sealing)
    Using usuario As DirectoryEntry = objDirEnt.Children.Add("CN=aaaaaa bbbbbbbbbb ccccccccc (aaaaaa.bbbbbb.ccccccccc)", "user")
        usuario.Properties("sAMAccountName").Value = "aaaaaa.bbbbbb.ccccccccc"
        usuario.Properties("userAccountControl").Value = AdsUserFlags.PasswordNotRequired
        usuario.Properties("name").Value = "aaaaaa bbbbbbbbbb ccccccccc"
        usuario.Properties("givenName").Value = "aaaaaa"
        usuario.Properties("sn").Value = "bbbbbbbbbb ccccccccc"
        usuario.CommitChanges()
    End Using
End Using
Run Code Online (Sandbox Code Playgroud)

sty*_*ish 9

根据这篇文章,这个字段的默认限制少于20个字符:http: //msdn.microsoft.com/en-us/library/ms679635.aspx 我没有尝试创建一个具有20chars sAMAccountName的用户但是也许它可以与Novell LDAP库一起使用.我不得不使用它,因为我们也需要支持其他LDAP服务. http://www.novell.com/coolsolutions/feature/11204.html

我还发现了这些帖子:https: //serverfault.com/questions/344815/how-to-add-a-user-in-active-directory-with-name-longer-than-20-characters