我试图进行LDAP问询,将所有属于组织单位的用户(OU=Employees
和OU=FormerEmployees
,而且我没有到任何地方。
我尝试使用<条码>拆开的Name进行搜索,但这似乎只是支持野心。 我知道,必须更加容易,但我的搜索努力没有产生任何结果。
我试图进行LDAP问询,将所有属于组织单位的用户(OU=Employees
和OU=FormerEmployees
,而且我没有到任何地方。
我尝试使用<条码>拆开的Name进行搜索,但这似乎只是支持野心。 我知道,必须更加容易,但我的搜索努力没有产生任何结果。
如果你在NET3.5和新版上读取,你可以使用 PrincipalSearcher
和“query-by-example”作为主人查询:
// create your domain context and define what container to search in - here OU=Employees
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN", "OU=Employees,DC=YourCompany,DC=com");
// define a "query-by-example" principal - here, we search for a UserPrincipal
// that is still active
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.Enabled = true;
// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
// find all matches
foreach(var found in srch.FindAll())
{
// do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
}
如果你有点,就绝对读到MSDN条款。 《网络框架》第3.5条: 说明如何最好地利用<编码>系统>的新特征。
如果你喜欢“旧”网络2.0风格的话,你需要建立一个基底<代码>目录><>代码>,该代码与你想要在座标中列举的物体相对应,然后你需要创建“名录Searcher
// create your "base" - the OU "FormerEmployees"
DirectoryEntry formerEmployeeOU = new DirectoryEntry("LDAP://OU=FormerEmployees,DC=YourCompany,DC=com");
// create a searcher to find objects inside this container
DirectorySearcher feSearcher = new DirectorySearcher(formerEmployeeOU);
// define a standard LDAP filter for what you search for - here "users"
feSearcher.Filter = "(objectCategory=user)";
// define the properties you want to have returned by the searcher
feSearcher.PropertiesToLoad.Add("distinguishedName");
feSearcher.PropertiesToLoad.Add("sn");
feSearcher.PropertiesToLoad.Add("givenName");
feSearcher.PropertiesToLoad.Add("mail");
// search and iterate over results
foreach (SearchResult sr in feSearcher.FindAll())
{
// for each property, you need to check where it s present in sr.Properties
if (sr.Properties["description"] != null && sr.Properties["description"].Count > 0)
{
string description = sr.Properties["description"][0].ToString();
}
}
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...