using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, Domain, UserName, Password)) { UserPrincipal U = new UserPrincipal(ctx); U.GivenName = strFirstName; U.Surname = strLastName; U.EmailAddress = strEmail; PrincipalSearcher srch = new PrincipalSearcher(U); foreach (var principal in srch.FindAll()) { var p = (UserPrincipal)principal; if (!User.Any(x => x.Email == p.EmailAddress)) { MyUserDataset.UserRow User = User.NewUserRow(); User.FirstName = p.GivenName; User.LastName = p.Surname; User.UserName = p.SamAccountName; User.Email = p.EmailAddress; User.AddUserRow(User); } } User.AcceptChanges(); }
I use the PrincipalContext class above to establish a connection to the target directory and specify credentials to perform directory operations.
Does anyone know how I can specify the connection time in the PrincipalContext Constructor ?, I am facing connection time problems, and I was wondering if I can control how long the connection time may expire.
source share