VB.Net“有一个命名违规”错误,打开ldap用于创建用户

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB.Net“有一个命名违规”错误,打开ldap用于创建用户相关的知识,希望对你有一定的参考价值。

我正在尝试使用目录服务将目录条目添加到openldap服务器。我看到的例子看起来很简单,但我不断收到错误“存在命名违规”。这条消息是什么意思?我该如何解决?

我已经包含了用于创建person容器的代码,ldif文件。

Public Function Ldap_Store_Manual_Registration(ByVal userName As String, ByVal firstMiddleName As String, ByVal lastName As String, ByVal password As String)

   Dim entry As DirectoryEntry = OpenLDAPconnection()  'OpenLDAPconnection() is DirectoryEntry(domainName, userId, password, AuthenticationTypes.SecureSocketsLayer) )

   Dim newUser As DirectoryEntry

   newUser = entry.Children.Add("ou=alumni", "organizationalUnit") 'also try with newUser = entry.Children.Add("ou=alumni,o=xxxx", "organizationalUnit") , also not working

   SetADProperty(newUser, "objectClass", "organizationalPerson") 
   SetADProperty(newUser, "objectClass", "person") 
   SetADProperty(newUser, "cn", userName)
   SetADProperty(newUser, "sn", userName)

   newUser.CommitChanges()
End Function

Public Shared Sub SetADProperty(ByVal de As DirectoryEntry, _
    ByVal pName As String, ByVal pValue As String)

    'First make sure the property value isnt "nothing"

    If Not pValue Is Nothing Then

        'Check to see if the DirectoryEntry contains this property already
        If de.Properties.Contains(pName) Then 'The DE contains this property

            'Update the properties value
            de.Properties(pName)(0) = pValue

        Else    'Property doesnt exist

            'Add the property and set it's value
            de.Properties(pName).Add(pValue)

        End If

    End If

End Sub

ldif文件:

version: 1

dn: cn=test3,ou=alumni,o=unimelb

objectClass: organizationalPerson

objectClass: person

objectClass: top

cn: test3

sn: test3 
答案

也许你需要包括这个?

SetADProperty(newUser, "objectClass", "top")

另外,检查organizationalPersonperson所需的字段是什么......你可能会遗漏一个。

另一答案

尝试:

Dim entry As New DirectoryEntry("LDAP://ou=alumni", etc.)
newUser = entry.Children.Add("cn=" + userName, "user")

以上是关于VB.Net“有一个命名违规”错误,打开ldap用于创建用户的主要内容,如果未能解决你的问题,请参考以下文章

PDF 生成后无法打开 (vb.net) (asp.net)

通过 LDAP 创建 LDS 用户时“指定的目录对象未绑定到远程资源”

vb.net 导出csv后数字格式问题

编程vb.net clipboard 剪切复制粘贴

ASP.NET - VB.NET - 更新 MS_Access 表

VB.Net中该怎么调用windows的API?