"The specified directory object is not bound to a remote resource" when creating LDS user via LDAP

StackOverflow https://stackoverflow.com/questions/14482043

Pregunta

I am accessing an AD LDS via LDAP and VB.Net and can create and organize groups without any issue. However, whenever I try to create a user I get the above error that the specified directory object is not bound to a remote resource. I've seen a few similar questions here on SO but those resolutions did not work for me. I get the same error when running any of the three blocks of code below:

Using System.DirectoryServices:

Dim rootEntry As DirectoryEntry = GetRootEntry()
Dim user As DirectoryEntry
Dim user_cn As String = String.Format("CN={0}{1}", firstName.Substring(0, 1), lastName)
Dim hosp_ou As String = BuildHospitalCN(HospitalName, HospitalID, "OU=Critical_Access_Hospitals")
user = rootEntry.Children.Find("OU=Users").Children.Find("OU=Critical_Access_Hospitals").Children.Find(hosp_ou).Children.Add(user_cn, "user")
With user
    .Properties("sAMAccountName").Value = String.Format("{0}{1}", firstName.Substring(0, 1), lastName)
    .Properties("givenName").Value = firstName
    .Properties("sn").Value = lastName
End With
user.CommitChanges()

Using System.DirectoryServices.AccountManagement:

Dim ctx As New PrincipalContext(ContextType.Domain)
Dim user As New UserPrincipal(ctx, _
                              String.Format("{0}{1}", firstName.Substring(0, 1), lastName), _
                              "password", _
                              True)
user.SamAccountName = String.Format("{0}{1}", firstName.Substring(0, 1), lastName)
user.GivenName = firstName
user.Surname = lastName
user.ExpirePasswordNow()
user.Save()

Using an example I found online specifically for AD LDS via LDAP:

Dim objADAM As DirectoryEntry
Dim objUser As DirectoryEntry
Dim strDisplayName As String
Dim strPath As String
Dim strUser As String
Dim strUserPrincipalName As String

strPath = ConfigurationManager.AppSettings("LDAP_ROOT").ToString

objADAM = New DirectoryEntry(strPath, _
                             ConfigurationManager.AppSettings("LDAP_USER"), _
                             ConfigurationManager.AppSettings("LDAP_PASS"), _
                             AuthenticationTypes.None)
objADAM.RefreshCache()

strUser = String.Format("CN={0}{1}", firstName.Substring(0, 1), lastName)
strDisplayName = String.Format("{0} {1}", firstName, lastName)
strUserPrincipalName = String.Format("{0}{1}@example.com", firstName.Substring(0, 1), lastName)

objUser = objADAM.Children.Add(strUser, "user")
objUser.Properties("displayName").Add(strDisplayName)
objUser.Properties("userPrincipalName").Add(strUserPrincipalName)
objUser.CommitChanges()

Any help would be greatly appreciated!

¿Fue útil?

Solución

sAMAccountName is not a valid attribute in this LDS repository.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top