我正在使用.Net库的System.DirectoryServices.AccountManagement部分连接到ActiveDirectory.
在GroupPrincipal对象上调用GetMembers()并过滤结果后,我现在有一个UserPrincipal对象的集合
GroupPrincipal myGroup; // population of this object omitted here
foreach (UserPrincipal user in myGroup.GetMembers(false).OfType<UserPrincipal>())
{
Console.WriteLine(user.SamAccountName);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码示例将打印出"TestUser1"之类的用户名.我需要将这些与来自"DOMAIN\TestUser1"格式的另一个应用程序的列表进行比较.
如何从UserPrincipal对象获取"DOMAIN"部分?
我不能只是附加一个已知的域名,因为涉及多个域,我需要区分DOMAIN1\TestUser1和DOMAIN2\TestUser2.
如何检测我的程序是否在Active Directory环境中运行?
我正在使用C#和.Net 2.0
我有以下代码返回UserPrincipal但loginname从不包含域名.也没有"域名"或类似的属性.
如何从UserPrincipal或PrincipalSearcher域获取用户/返回的用户?
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal user = new UserPrincipal(ctx);
user.SamAccountName = txtSearch.Text;
PrincipalSearcher searcher = new PrincipalSearcher(user);
PrincipalSearchResult<Principal> results = searcher.FindAll();
foreach (UserPrincipal u in results)
{
Response.Write(u.Name + "<br />");
}
Run Code Online (Sandbox Code Playgroud)