How to set connection time when creating context - PrincipalContext

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.

+5
source share
1 answer

Well, I think the answer is not unfortunately. I dig the PrincipalContext source code, it used DirectoryEntry, which used the unsafe native System.DirectoryServices.Interop.UnsafeNativeMethods.ADsOpenObject native method to open an LDAP connection.

Like this blog: http://blogs.msdn.com/b/dsadsi/archive/2012/06/06/how-to-specify-timeout-for-ldap-bind-in-net.aspx , there is no way configure timeout on ADsOpenObject. However, he also noted that when using LdapConnection directly, you can set a timeout. In this case, you cannot use the PrincipalContext user.

+1
source

Source: https://habr.com/ru/post/1214715/


All Articles