2
votes

I am having an issue with the DirectoryEntry object where it's taking a long time trying to connect to to a dead AD server and eventually failing. Is it possible to set a timeout so that if its not able to connect within a specific time, it just comes out to try the next one?

2

2 Answers

0
votes

There is no timeout option for DirectoryEntry directly.

You can use DirectorySearcher and set the ClientTimeout (even if you're only looking for one object by path). Or do your directory operation on a new thread or BackgroundWorker and control your own timeout.

0
votes

I suggest you create your own LdapConnection to the server. This will allow you to specify a timeout and finely control which method you are using.

Also note that without going to this lower level, the .NET classes will attempt to use LDAP+SSL, then Kerberos, and finally RPC. You may be experiencing delays/timeouts during this process.