我们有一个完全信任运行的 WPF 应用程序。
应用程序的一部分会检查 Windows AD 组的成员资格。
这在 Windows 7 计算机上运行良好,但在 Windows XP 计算机上则不行。
错误发生在以下行:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain name");
最佳答案
根据文章Managing Directory Security Principals in the .NET Framework 3.5 ,可能不需要“域名”变量。也就是说,如果您访问与应用程序位于同一域中的 Active Directory,则不需要域名。
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.
问题的解决方案或解决方法(至少在 XP 和 W7 上对我有用)是以下更改:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, null);
关于c# - Windows XP 上出现PrincipalServerDownException,但 Windows 7 上没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10894031/