Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
LdapConnection Bind Timeout

Is there a way to set the bind timeout on an LDAP connection using the System.DirectoryServices.Protocols.LdapConnection that comes with .NET? Not to be confused with the connection timeout (which is the Timeout property). Essentially, I need to set the LDAP_OPT_TIMELIMIT as described here.

LdapSessionOptions seems like the place for that, but near as I can see this particular option isn't present. Is there something else I'm missing?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Here's the solution I came up with:

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);
}

This works, but I certainly don't love all that reflection. Or the DllImport, although the .NET library uses that under the covers anyway, so I feel like that's not as big a deal.

Per the comments below, it's also good to note here that due to the dependency on Wldap32.dll, this would appear to be Windows-only and not suitable for cross-platform.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda