本文介绍了如何在ASP.NET C#中获取所有域用户#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我是以上概念的新手。我想要所有域名用户的名字,请给我一个想法或解决方案
我尝试过:
我有Active目录的openQuery概念,如****'****'****'** **'****'****'
Hello,
I new to above concept.I want all domain users name ,Please give me idea or solution
What I have tried:
I have Active directory's openQuery concept like****'****'****'****'****'****'
GO
EXEC master.dbo.sp_addlinkedserver @server = N'ADSI_12', @srvproduct=N'Active Directory Service Interfaces', @provider=N'ADSDSOObject', @datasrc=N'adsdatasource'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'ADSI_12',@useself=N'False',@locallogin=NULL,@rmtuser=N'JKMARLOCAL\SUJATA.SHINDE',@rmtpassword='*********'
并选择命令如
and select command like
SELECT * FROM OpenQuery (
ADSI_12,
'SELECT displayName, telephoneNumber, mail, mobile, facsimileTelephoneNumber
FROM ''LDAP://JKUMARLOCAL.com,DC=JKUMARLOCAL,DC=com''
WHERE objectClass = ''SUJATA.SHINDE''
') AS tblADSI
order BY displayname
但我不符合我的要求
but i does not meet my requirment
推荐答案
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// define a "query-by-example" principal - here, we search for all users
UserPrincipal qbeUser = new UserPrincipal(ctx);
// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
// find all matches
foreach (var found in srch.FindAll())
{
//Label1.Text = found.Name;
// do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
DropDownList1.Items.Add(found.Name);
DropDownList2.Items.Add(found.UserPrincipalName);
}
这篇关于如何在ASP.NET C#中获取所有域用户#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!