我正在使用blow代码从本地计算机(虚拟桌面)客户端在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发布于 2016-12-13 03:24:25
我知道这个问题很老了,所以你可能已经找到了解决方案。但对于其他通过谷歌来到这里的人来说:
如果您告诉我们哪一行抛出了错误,这会有所帮助,但我猜是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();https://stackoverflow.com/questions/37221767
复制相似问题