AD LDS错误“服务器上没有此类对象”

时间:2016-05-14 02:16:09

标签: c# asp.net-mvc adlds

我正在使用管道代码从我的本地计算机(虚拟桌面)客户端在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

1 个答案:

答案 0 :(得分:2)

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

如果你告诉我们哪一行引发错误会有所帮助,但我的猜测是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();