![](/img/trans.png)
[英]How can I grant permissions for a FTP Folder for users of the active directory
[英]How I get the users of a folder in Active Directory?
嗨,我想建立一個LDAP查詢,我如何將所有用戶放在一個文件夾中...例如:
OU=DBG,OU=THINCLIENT,OU=NPS,OU=services,DC=YourDomain,DC=com
我想從Active Directory中將所有用戶ins放在此文件夾中。 為此,我有一個查詢,但不知道如何獲取此文件夾的用戶:(
(&(objectClass=user)(objectCategory=user)(??????))
如果使用的是.NET 3.5或更高版本,則可以使用PrincipalSearcher
和“按示例查詢”主體進行搜索:
// create your domain context
string container = "OU=DBG,OU=THINCLIENT,OU=NPS,OU=services,DC=YourDomain,DC=com";
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YourDomain", container))
{
// define a "query-by-example" principal - here, we search for UserPrincipal
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())
{
// do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
}
}
如果您還沒有-一定要閱讀MSDN文章.NET Framework 3.5中的 “ 管理目錄安全性主體”,它很好地展示了如何充分利用System.DirectoryServices.AccountManagement
中的新功能。 或參閱System.DirectoryServices.AccountManagement命名空間上的MSDN文檔 。
您需要在引用中添加對System.DirectoryServices.AccountManagement
程序集的引用,並且需要這樣的一行:
using System.DirectoryServices.AccountManagement;
在您的代碼隱藏文件的頂部,以使其正常工作。
您可以在UserPrincipal
上指定任何屬性,並將它們用作PrincipalSearcher
“按示例查詢”。
您可以使用System.DirectoryServices命名空間。
DirectoryEntry scope = new DirectoryEntry("LDAP://OU=DBG,OU=THINCLIENT,OU=NPS,OU=services,DC=YourDomain,DC=com");
string filter = "(&(objectClass=user)(objectCategory=user))";
string[] attrs = new string[]{"samaccountname","whencreated"};
DirectorySearcher searcher = new DirectorySearcher(scope,filter,attrs);
foreach(SearchResult result in searcher.FindAll())
{
//result.Properties["attribute"][0].ToString();
}
嘗試
(&(objectClass=user)(objectCategory=user)(homeDirectory=*YourFolderName*))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.