1
基本上我正在創建一個員工變更請求表單,並希望加載列出的選擇中的電子郵件組(用於添加/刪除成員資格)我在Visual C#中工作並試圖創建一個使用目錄服務完成此操作的單獨類。當我將該類添加到App_Code文件夾時,它不再能夠找到System.DirectoryServices並給我一個錯誤。我錯過了什麼?如何在我的Web表單中使用目錄服務?
基本上我正在創建一個員工變更請求表單,並希望加載列出的選擇中的電子郵件組(用於添加/刪除成員資格)我在Visual C#中工作並試圖創建一個使用目錄服務完成此操作的單獨類。當我將該類添加到App_Code文件夾時,它不再能夠找到System.DirectoryServices並給我一個錯誤。我錯過了什麼?如何在我的Web表單中使用目錄服務?
如果您使用的是.NET 3.5及更高版本,則應檢查System.DirectoryServices.AccountManagement
(S.DS.AM)命名空間。您需要將它作爲.NET參考添加到您的項目中。
閱讀所有關於它在這裏:
Managing Directory Security Principals in the .NET Framework 3.5
基本上,你可以定義域範圍內,並可以輕鬆地查找用戶和/或組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中的用戶和羣組一起玩:
你得到的錯誤是什麼? – zeroef 2011-05-23 15:16:04
這聽起來像你正在使用一個網站「項目」。我建議使用Web應用程序項目,至少對於任何不重要的東西。 – 2011-05-23 15:22:26