0

我正在通过 LDAP 和 VB.Net 访问 AD LDS,并且可以毫无问题地创建和组织组。但是,每当我尝试创建用户时,我都会收到上述错误,specified directory object is not bound to a remote resource.我在 SO 上看到了一些类似的问题,但这些解决方案对我不起作用。运行以下三个代码块中的任何一个时,我都会遇到相同的错误:

使用 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()

使用 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()

使用我在网上找到的一个通过 LDAP 专门针对 AD LDS 的示例:

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()

任何帮助将不胜感激!

4

1 回答 1

0

sAMAccountName 不是此 LDS 存储库中的有效属性。

于 2013-01-24T14:15:23.227 回答