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

问题描述 投票:1回答:2

我正在尝试使用目录服务将目录条目添加到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 
vb.net ldap
2个回答
1
投票

也许你需要包括这个?

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

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


0
投票

尝试:

Dim entry As New DirectoryEntry("LDAP://ou=alumni", etc.)
newUser = entry.Children.Add("cn=" + userName, "user")
© www.soinside.com 2019 - 2024. All rights reserved.