我正在尝试改编代码从VB到C#的视窗窗体。我还在尝试大致掌握DFS的概念,以及如何在Windows窗体中操作它。
VB使用GetObject("LDAP://RootDSE")函数通过DirectorySearcher在Active Directory中搜索共享。我已经调整了其他函数,这些函数使用相同的对象从用户id返回一个组,以及检查组是否已经存在(使用GroupPrincipal)。它们通常是这样的:
public static UserPrincipal GetUserPrincipal(string userId) {
PrincipalContext context = new PrincipalContext(ContextType.Domain);
UserPrincipal user = new UserPrincipal(context);
user.Name = userId;
PrincipalSearcher searcher = new PrincipalSearcher(user);
return searcher.FindOne() as UserPrincipal;
}但是,我找不到任何包含我正在使用的关键字的文档,但我正在尝试获取属于DFS名称空间的目录列表(我想)。
以下是VB中的(修改后)代码:
Public Function GetDfsNamespaces() As List(Of String)
Dim objRootDSE = GetObject("LDAP://RootDSE")
Dim domain As String = objRootDSE.Get("DefaultNamingContext")
Dim entry As New DirectoryEntry("LDAP://CN=DFs-Configuration,CN=System," & domain)
Dim searcher As New DirectorySearcher(entry)
searcher.PropertiesToLoad.Add("cn")
searcher.Filter = "(objectClass=msDFS-NamespaceAnchor)"
searcher.SearchScope = SearchScope.Subtree
Dim results As SearchResultCollection = searcher.FindAll()
Dim strResults As New List(Of String)
For Each result In results
strResults.Add(result.Properties("cn")(0))
Next
return strResults
End Function我试着研究了UserPrincipal、GroupPrincipal和ComputerPrincipal的源代码,但没有弄清楚如何扩展Principal对象来获取目录或其他东西。
发布于 2013-04-03 04:17:02
前两行应该是这样的:
string domain;
using (DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"))
{
domain = rootDSE.Properties["defaultNamingContext"].Value.ToString();
}剩下的代码应该很容易转换。
https://stackoverflow.com/questions/15773119
复制相似问题