1

我正在使用打击代码从我的本地计算机(虚拟桌面)客户端在 AD LDS 中创建帐户/用户。在我的本地下面的代码工作正常但是在将代码部署到与安装 AD LDS 的位置不同的其他服务器之后,它会抛出错误“服务器上没有这样的对象”下面给出的完整响应标头。

 Var host = "Hostname";// soemthing like SV1DCVDEVDB789 where AD LDS is instaed
 var port = 389;//Port Number
 var machineName = string.Format("{0}:{1}", host, port);
 var container = "CN=PSExtUser,CN=PSADLDSPartition1,DC=PS,DC=COM";
 var principalContext = new    PrincipalContext(ContextType.ApplicationDirectory, machineName, container);

//Check id user already exist

UserPrincipal usr = UserPrincipal.FindByIdentity(principalContext, userId);


//if usr is null create new user as below code

      UserPrincipal newUser = new UserPrincipal(principalContext);
                newUser.Name = userId;
                newUser.UserPrincipalName = userId;
                newUser.SetPassword(pwd.ToString());
                newUser.Enabled = false;
                newUser.Save();



////REsponse obtained 





[DirectoryServicesCOMException (0x80072030): There is no such object on the server.
]
   System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +597561
   System.DirectoryServices.DirectoryEntry.Bind() +44
   System.DirectoryServices.DirectoryEntry.get_AdsObject() +42
   System.DirectoryServices.DirectoryEntry.get_Options() +42
   System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit() +351

[PrincipalOperationException: There is no such object on the server.
]
   System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit() +495548
   System.DirectoryServices.AccountManagement.PrincipalContext.DoApplicationDirectoryInit() +61
   System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() +184
   System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() +42
4

1 回答 1

2

我知道这个问题很老,所以你可能已经找到了解决方案。但对于通过 Google 来到这里的其他人:

如果您告诉我们哪一行抛出错误会有所帮助,但我猜它是 SetPassword。设置该密码要求该帐户已经存在。所以把你的SetPassword移到你的Save().

我相信同样如此Enabled

  UserPrincipal newUser = new UserPrincipal(principalContext);
            newUser.Name = userId;
            newUser.UserPrincipalName = userId;
            newUser.Save();

            newUser.Enabled = false;
            newUser.SetPassword(pwd.ToString());
            newUser.Save();
于 2016-12-12T19:24:24.670 回答