[英]How can I use Directory Services in my Web Form?
基本上,我正在創建一個員工變更請求表單,並希望在列出的選擇中加載電子郵件組(用於添加/刪除成員資格),我正在Visual C#中工作,並試圖創建一個單獨的使用目錄服務來完成此任務的類。 當我將類添加到App_Code文件夾時,它不再能夠找到System.DirectoryServices並給我一個錯誤。 我想念什么?
如果您使用的是.NET 3.5及更高版本,則應簽出System.DirectoryServices.AccountManagement
(S.DS.AM)命名空間。 您需要將其作為.NET參考添加到您的項目中。
在這里閱讀所有內容:
基本上,您可以定義域上下文並輕松找到AD中的用戶和/或組:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");
if(user != null)
{
// do something here....
}
// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");
// if found....
if (group != null)
{
// iterate over members
foreach (Principal p in group.GetMembers())
{
Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
// do whatever you need to do to those members
}
}
新的S.DS.AM使得與AD中的用戶和組玩起來非常容易:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.