Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Tiempo de espera de vinculación de LdapConnection

¿Hay alguna manera de establecer el tiempo de espera de vinculación en una conexión LDAP usando System.DirectoryServices.Protocols.LdapConnection que viene con .NET? No debe confundirse con el tiempo de espera de la conexión (que es la propiedad Timeout ). Esencialmente, necesito configurar LDAP_OPT_TIMELIMIT como se describe aquí .

LdapSessionOptions parece ser el lugar para eso, pero por lo que puedo ver, esta opción en particular no está presente. ¿Hay algo más que me estoy perdiendo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Aquí está la solución que se me ocurrió:

 private const int LDAP_OPT_TIMELIMIT = 0x04; [DllImport("Wldap32.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ldap_set_optionW", CharSet = CharSet.Unicode)] private static extern int ldap_set_option([In] IntPtr handle, [In] int option, [In] ref int inValue); private static void SetLdapConnectionBindTimeout(LdapConnection conn, int timeoutSeconds) { // We need the underlying LdapConnection handle; that's internal, so reflection here we go. var handleField = typeof(LdapConnection).GetField("ldapHandle", BindingFlags.NonPublic | BindingFlags.Instance); var handleWrapper = handleField.GetValue(conn); // That handle object is itself a wrapper class around the IntPtr we actually need. // The wrapper class is internal, and so is the IntPtr, so more reflection. var internalHandleField = handleWrapper.GetType().GetField("handle", BindingFlags.NonPublic | BindingFlags.Instance); var internalHandle = (IntPtr)internalHandleField.GetValue(handleWrapper); // Now we can set. ldap_set_option(internalHandle, LDAP_OPT_TIMELIMIT, ref timeoutSeconds); }

Esto funciona, pero ciertamente no me encanta toda esa reflexión. O el DllImport , aunque la biblioteca .NET lo usa de todos modos, así que siento que no es tan importante.

Según los comentarios a continuación, también es bueno tener en cuenta aquí que, debido a la dependencia de Wldap32.dll , parece ser solo para Windows y no apto para varias plataformas.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!