本文介绍了当我需要一个域名和一个域容器创建PrincipalContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在开发一个C#.NET Framework库访问Active Directory。

I'm developing a C# .NET Framework library to access active directory.

相反,我所要做的事情是让所有的AD用户,我看到:

One of the things that I have to do is to get all AD users, and I see that:

PrincipalContext principalContext =
    new PrincipalContext(ContextType.Domain,
                            domainName.Trim(),
                            domainContainer.Trim());

PrincipalContext principalContext = new PrincipalContext(ContextType.Domain);

返回相同的用户使用此code:

Returns the same users with this code:

// define a "query-by-example" principal - here, we search for all users
UserPrincipal qbeUser = new UserPrincipal(principalContext);

// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

// find all matches
foreach (var found in srch.FindAll())
{
    UserPrincipal user = found as UserPrincipal;
    if (user != null)
    {
        Console.WriteLine(user.SamAccountName);
    }
}

当我需要使用域名和域容器?

When do I need to use a Domain Name and a Domain Container?

推荐答案

在使用

PrincipalContext principalContext = new PrincipalContext(ContextType.Domain);

这将连接到当前的背景下,一般谁跑的应用程序的用户登录,如果目前的情况下是本地用户没有连接到域将抛出一个异常的域的域。

It will connect to the domain of the current context, usually the domain the user who ran the application is logged into, or will throw an exception if the current context is a local user not connected to a domain.

在使用

PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, domainName.Trim(), domainContainer.Trim());

域属性允许您连接到比当前上下文的另一个域,假设目前的情况下拥有的权限,或者您提供有效凭据。因此,例如在环境中存在多个域存在林或域信任,您可以指定另一个域打击,而不是一个用户的成员进行查询。

The domain property allows you to connect to a domain other than the one of the current context, assuming the current context has permissions or you supply valid credentials. So for example in an environment where there is multiple domains in a forest or domain trusts in place, you can specify another domain to run queries against instead of the one the user is a member of.

容器的属性使用 DomainContext 到指定容器限制所有查询。

The container properties limits all queries using that DomainContext to the specified container.

这篇关于当我需要一个域名和一个域容器创建PrincipalContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 00:07