【发布时间】:2014-12-29 19:04:21
【问题描述】:
我有 2 个域之间存在信任关系。由于配置的信任,我在其中一个域中有一个 Active Directory 帐户,该帐户在另一个域中也具有权限。在我的应用程序中,我需要访问这两个域并列出其中的用户。
我的开发计算机不在上述域中,我无法将其添加到这些域中。 目前我正在使用以下代码列出创建我的帐户的域中的用户:
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "192.168.2.11", “Login1”, “pass1”))
{
using (UserPrincipal searchPrincipal = new UserPrincipal(pc))
{
searchPrincipal.Name = "*";
using (PrincipalSearcher searcher = new PrincipalSearcher(searchPrincipal))
{
using (PrincipalSearchResult<Principal> principals = searcher.FindAll())
{
foreach (UserPrincipal principal in principals)
{
Console.WriteLine(principal.Name);
}
}
}
}
}
如果我在不在其中一个域中的计算机上运行代码,如何调整我的代码以列出来自两个域的用户?
【问题讨论】:
标签: c# authentication active-directory windows-authentication directoryservices