Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用PrincipalSearcher获取DFS共享_C#_Winforms_Active Directory_Microsoft Distributed File System - Fatal编程技术网

C# 使用PrincipalSearcher获取DFS共享

C# 使用PrincipalSearcher获取DFS共享,c#,winforms,active-directory,microsoft-distributed-file-system,C#,Winforms,Active Directory,Microsoft Distributed File System,我正在尝试将VB中的代码改编成Windows窗体中的C。我仍在试图从总体上理解DFS的概念,以及如何从Windows窗体操作它 VB使用GetObject(“LDAP://RootDSE”)函数使用DirectorySearcher搜索Active Directory中的共享。我修改了其他函数,这些函数使用同一对象从用户id返回UserPrincipal,并检查组是否已经存在(使用GroupPrincipal)。这些通常是这样的: public static UserPrincipal GetU

我正在尝试将VB中的代码改编成Windows窗体中的C。我仍在试图从总体上理解DFS的概念,以及如何从Windows窗体操作它

VB使用
GetObject(“LDAP://RootDSE”)
函数使用
DirectorySearcher
搜索Active Directory中的共享。我修改了其他函数,这些函数使用同一对象从用户id返回
UserPrincipal
,并检查组是否已经存在(使用
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;
}
        string domain;
        using (DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"))
        {
            domain = rootDSE.Properties["defaultNamingContext"].Value.ToString();
        }
但是,我找不到任何包含我正在使用的关键字的文档,但我正在尝试获取属于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
对象以获取目录或其他内容。

前两行应该是这样的:

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;
}
        string domain;
        using (DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"))
        {
            domain = rootDSE.Properties["defaultNamingContext"].Value.ToString();
        }

剩下的代码应该可以直接转换。

前两行应该是这样的:

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;
}
        string domain;
        using (DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"))
        {
            domain = rootDSE.Properties["defaultNamingContext"].Value.ToString();
        }

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

Wow,这很容易。我读过一些关于PrincipalSearcher的东西,因为它更快?它随.NET3.5而来,你认为有没有一种方法可以在新对象上实现这一点?实际上,这些对象通常速度较慢。坚持使用DirectoryEntry/DirectorySearcher。哇,这很简单。我读过一些关于PrincipalSearcher的东西,因为它更快?它随.NET3.5而来,你认为有没有一种方法可以在新对象上实现这一点?实际上,这些对象通常速度较慢。坚持使用DirectoryEntry/DirectorySearcher。