首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PrincipalSearcher获取DFS共享

使用PrincipalSearcher获取DFS共享
EN

Stack Overflow用户
提问于 2013-04-03 03:51:42
回答 1查看 1K关注 0票数 1

我正在尝试改编代码从VB到C#的视窗窗体。我还在尝试大致掌握DFS的概念,以及如何在Windows窗体中操作它。

VB使用GetObject("LDAP://RootDSE")函数通过DirectorySearcher在Active Directory中搜索共享。我已经调整了其他函数,这些函数使用相同的对象从用户id返回一个组,以及检查组是否已经存在(使用GroupPrincipal)。它们通常是这样的:

代码语言:javascript
复制
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中的(修改后)代码:

代码语言:javascript
复制
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

我试着研究了UserPrincipalGroupPrincipalComputerPrincipal的源代码,但没有弄清楚如何扩展Principal对象来获取目录或其他东西。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-03 04:17:02

前两行应该是这样的:

代码语言:javascript
复制
        string domain;
        using (DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"))
        {
            domain = rootDSE.Properties["defaultNamingContext"].Value.ToString();
        }

剩下的代码应该很容易转换。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15773119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档