AD LDS error "There is no such object on the server"

1

I am using blow code to create account/user in AD LDS from my local machine (virtual desktop) client. In my local below code works fine But after deploying code to some other server which is different from where AD LDS is installed it throws error "There is no such object on the server" Complete response header given below .

 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
c#
asp.net-mvc
adlds
asked on Stack Overflow May 14, 2016 by FHN

1 Answer

2

I know this question is old, so you may have found the solution. But for others that come here through Google:

It helps if you tell us which line is throwing the error, but my guess it's the SetPassword. Setting that password requires that the account already exists. So move your SetPassword to after your Save().

I believe the same is true of Enabled as well.

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

            newUser.Enabled = false;
            newUser.SetPassword(pwd.ToString());
            newUser.Save();
answered on Stack Overflow Dec 12, 2016 by Gabriel Luci

User contributions licensed under CC BY-SA 3.0