Pregunta

We have a WPF application that runs in full trust.

Part of the application checks the membership of a Windows AD group.

This works fine on a Windows 7 machine, but not on a Windows XP machine.

The error occurs on the following line:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain name");
¿Fue útil?

Solución

According to the article Managing Directory Security Principals in the .NET Framework 3.5, the "domain name" variable might not be needed. That is, if you are accessing an Active Directory in the same domain as your application, the domain name is not needed.

You use the name parameter on the PrincipalContext constructor in order to provide the name of the specific directory to connect to. This can be the name of a specific server, machine, or domain. It's important to note that if this parameter is null, AccountManagement will attempt to determine a default machine or domain for the connection based on your current security context.

The solution or workaround to the problem (at least what worked for me on both XP and W7) is the following change:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, null);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top