0

Creating an instance of a PrincipalSearcher for accessing a local ActiveDirectory takes about 11 - 22 seconds. Interestingly the time is always 11 or 22 seconds, +/- a few milliseconds. The OU I'm trying to read out consists of not more than 30 users and 20 groups. If I understand it right the AD is completely read during the creation of the PrincipalSearcher. But because my AD is tiny I would not expect it to take that long. Am I doing something wrong or is this an expected behavior?


This is the test code I use to reproduce the described behavior.

const string name = "localhost:389";
const string container = "OU=OUNAME,DC=DCNAME,DC=local";
var principalContext = new PrincipalContext(ContextType.ApplicationDirectory, name, container);
var userPrincipal = new UserPrincipal(principalContext);
// The next call takes about 22 - 44 seconds
var principalSearcher = new PrincipalSearcher(userPrincipal);
var result = principalSearcher.FindAll();

When I do a performance profiling I get the following result: Performance Profiling Results


UPDATE #1:

The local AD is done with AD LDS and I found this question that seems to describe a similar problem. But I have both, the AD and the application, running on the same machine and I'm using localhost or 127.0.0.1. So this did not helped in my case.


UPDATE #2:

If I'm no longer connected to the company's domain, the same code takes less that 100ms. What could cause that different behavior? And more important, how can I overcome that behavior while connected to the domain?

Letho
  • 48
  • 9
  • Usually these delay issues in Net Library is when a client attempts to go through a proxy. The delay is due to waiting for the proxy timeout to occur and then code usually works without proxy. The solution is to disable the proxy check. See if this helps : https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/disable-http-proxy-auth-features?force_isolation=true – jdweng May 10 '22 at 10:12
  • Thanks. I tried the option to disable the WPAD but that did not made a difference. – Letho May 10 '22 at 15:36

1 Answers1

0

Try using the options parameter of the PrincipalContext constructor and see if some combination solves the problem for you.

The default (if you don't specify anything) is:

ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing

But see what combination of ContextOptions makes a difference, if any.

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84