相关疑难解决方法(0)

C#Active Directory:获取用户的域名?

我知道之前曾问过这类问题,但其他方法现在都让我失望了.

正如我们的Windows服务轮询AD,给定一个LDAP(即LDAP://10.32.16.80)和该AD服务器中要搜索的用户组列表.它检索这些给定组中的所有用户,以递归方式搜索这些组以获取更多组.然后将每个用户添加到另一个应用程序认证用户列表中.

这部分应用程序运行成功.但是,我们需要每个用户的友好域名(即他们登录DOMAIN /用户名的一部分)

因此,如果有一个用户属于TEST域,名为Steve:TEST/steve就是他的登录名.我能够在广告中找到史蒂夫,但是我还需要将"TEST"与他的AD信息一起存储.

再一次,通过使用目录搜索器和我给出的LDAP IP,我可以找到'史蒂夫',但是考虑到LDAP IP,我如何才能找到友好的域名?

当我尝试以下代码时,我在尝试访问'defaultNamingContext'时遇到错误:

System.Runtime.InteropServices.COMException(0x8007202A):身份验证机制未知.

这是代码:

    private string SetCurrentDomain(string server)
    {
        string result = string.Empty;
        try
        {
            logger.Debug("'SetCurrentDomain'; Instantiating rootDSE LDAP");
            DirectoryEntry ldapRoot = new DirectoryEntry(server + "/rootDSE", username, password);
            logger.Debug("'SetCurrentDomain'; Successfully instantiated rootDSE LDAP");

            logger.Debug("Attempting to retrieve 'defaultNamingContext'...");
            string domain = (string)ldapRoot.Properties["defaultNamingContext"][0]; //THIS IS WHERE I HIT THE COMEXCEPTION
            logger.Debug("Retrieved 'defaultNamingContext': " + domain);
            if (!domain.IsEmpty())
            {

                logger.Debug("'SetCurrentDomain'; Instantiating partitions/configuration LDAP entry");
                DirectoryEntry parts = new DirectoryEntry(server + "/CN=Partitions,CN=Configuration," + domain, username, password);

                logger.Debug("'SetCurrentDomain'; …
Run Code Online (Sandbox Code Playgroud)

c# dns active-directory comexception

23
推荐指数
3
解决办法
8万
查看次数

标签 统计

active-directory ×1

c# ×1

comexception ×1

dns ×1