如何获取Active Directory中的组的完整列表?ASP.NET如何获取Active Directory中的组列表
19
A
回答
33
退房的System.DirectoryServices(一个ASP.NET 2.0参考):
C#-example获得团体:
using System.DirectoryServices;
public class test
{
private void main()
{
foreach (string @group in GetGroups())
{
Debug.Print(@group);
}
}
public List<string> GetGroups()
{
DirectoryEntry objADAM = default(DirectoryEntry);
// Binding object.
DirectoryEntry objGroupEntry = default(DirectoryEntry);
// Group Results.
DirectorySearcher objSearchADAM = default(DirectorySearcher);
// Search object.
SearchResultCollection objSearchResults = default(SearchResultCollection);
// Results collection.
string strPath = null;
// Binding path.
List<string> result = new List<string>();
// Construct the binding string.
strPath = "LDAP://stefanserver.stefannet.local";
//Change to your ADserver
// Get the AD LDS object.
try
{
objADAM = new DirectoryEntry(strPath);
objADAM.RefreshCache();
}
catch (Exception e)
{
throw e;
}
// Get search object, specify filter and scope,
// perform search.
try
{
objSearchADAM = new DirectorySearcher(objADAM);
objSearchADAM.Filter = "(&(objectClass=group))";
objSearchADAM.SearchScope = SearchScope.Subtree;
objSearchResults = objSearchADAM.FindAll();
}
catch (Exception e)
{
throw e;
}
// Enumerate groups
try
{
if (objSearchResults.Count != 0)
{
foreach (SearchResult objResult in objSearchResults)
{
objGroupEntry = objResult.GetDirectoryEntry();
result.Add(objGroupEntry.Name);
}
}
else
{
throw new Exception("No groups found");
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return result;
}
}
VB-例如获得团体:
Imports System.DirectoryServices
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each group As String In GetGroups()
Debug.Print(group)
Next
End Sub
Public Function GetGroups() As List(Of String)
Dim objADAM As DirectoryEntry ' Binding object.
Dim objGroupEntry As DirectoryEntry ' Group Results.
Dim objSearchADAM As DirectorySearcher ' Search object.
Dim objSearchResults As SearchResultCollection ' Results collection.
Dim strPath As String ' Binding path.
Dim result As New List(Of String)
' Construct the binding string.
strPath = "LDAP://stefanserver.stefannet.local" 'Change to your ADserver
' Get the AD LDS object.
Try
objADAM = New DirectoryEntry(strPath)
objADAM.RefreshCache()
Catch e As Exception
Throw e
End Try
' Get search object, specify filter and scope,
' perform search.
Try
objSearchADAM = New DirectorySearcher(objADAM)
objSearchADAM.Filter = "(&(objectClass=group))"
objSearchADAM.SearchScope = SearchScope.Subtree
objSearchResults = objSearchADAM.FindAll()
Catch e As Exception
Throw e
End Try
' Enumerate groups
Try
If objSearchResults.Count <> 0 Then
Dim objResult As SearchResult
For Each objResult In objSearchResults
objGroupEntry = objResult.GetDirectoryEntry
result.Add(objGroupEntry.Name)
Next objResult
Else
Throw New Exception("No groups found")
End If
Catch e As Exception
Throw New Exception(e.Message)
End Try
Return result
End Function
End Class
1
Microsoft .NET Framework提供了一个与Active Directory配合使用的标准库:System.DirectoryServices namespace System.DirectoryServices.dll中。
微软建议使用从System.DirectoryServices命名空间两大类:的DirectoryEntry和的DirectorySearcher。在大多数情况下,仅使用DirectorySearcher类就足够了。
您可以在此CodeProject article中找到一些示例。
相关问题
- 1. .NET Active Directory - 获取特定Active Directory组中的用户列表
- 2. 如何获取Active Directory组中的组的列表
- 3. 获取Active Directory中的用户列表
- 4. 如何获取Active Directory中的用户组? (c#,asp.net)
- 5. 如何获取未连接到域的Active Directory域组列表
- 6. 从Active Directory获取asp.net web表单C#
- 7. 如何使用C#获取Active Directory中所有域的列表
- 8. 获取Active Directory中的用户组
- 9. 取从Active Directory组
- 10. 使用PHP获取Active Directory组的用户列表
- 11. 从Active Directory获取
- 12. 如何获取Active Directory中“成员”选项卡中的组
- 13. 如何从.NET Active Directory组中获取组名称?
- 14. 如何获取属于Active Directory中的组的用户?
- 15. 获取用户列表从Active Directory在给定AD组
- 16. 如何获取Active Directory中的用户组?
- 17. LDAP:如何获取Active Directory中的所有组?
- 18. 从Active Directory组获取用户
- 19. Asp.net中的Active Directory C#
- 20. 如何在Active Directory中获得用户组后,获取组的SID?
- 21. 如何在ASP.NET MVC中使用Active Directory
- 22. 列出所有Active Directory组
- 23. 从Azure Active Directory获取mailNickname
- 24. 使用C#获取Active Directory中组成员列表的快速方法
- 25. ASP.NET Active Directory搜索
- 26. 获取Active Directory中的所有用户
- 27. 属于Active Directory域中其他组的成员的列表组
- 28. Active Directory用户列表
- 29. 如何使用PrincipalContext获取Active Directory动态通讯组?
- 30. 如何获取Azure Active Directory角色或用户组
大东西,对我来说就像一个魅力! – 2009-06-25 08:04:39