【问题标题】:DistinguishedName attribute of Active DirectoryActive Directory 的 DistinguishedName 属性
【发布时间】:2023-04-04 20:48:01
【问题描述】:

这是我的代码:

public bool ActiveDirectoryAuthenticate(string username, string password)
{
   var result = false;

   using (var entry = new DirectoryEntry("LDAP://*****/DC=******,DC=biz",username,password,AuthenticationTypes.Secure))
   {
       var searcher = new DirectorySearcher(entry){Filter = "objectClass=user"};

       try
       {
           var sr = searcher.FindOne();
           var PathDic = sr.Properties["distinguishedName"][0].ToString();
           result = true;
       }
       catch (Exception exception)
       {
       }
    }

    return result;
}

问题是

sr.Properties["distinguishedName"][0].ToString();

没有返回正确的值。

请帮帮我

【问题讨论】:

  • 返回什么? 正确的值是多少??
  • 它只返回服务器名称和域名,但我想返回我创建的目录
  • 您能否向我们展示一个示例并解释您的期望/想要什么?我还是不明白你的问题到底是什么......
  • 正确:CN=BANK.Members,OU=MBank,OU=Development,OU=Technical,OU=pt,DC=pt,DC=biz 不正确:CN=Administrator,CN=Users,DC =pt,DC=biz

标签: c# asp.net .net active-directory


【解决方案1】:

只是一个想法,但您不需要像这样放置 value

var PathDic = sr.Properties["distinguishedName"][0].Value.ToString();

【讨论】:

    【解决方案2】:

    我的问题解决了:

    public bool ActiveDirectoryAuthenticate(string username, string password)
        {
            var result = false;
            using (
                var entry = new DirectoryEntry("LDAP://PT/DC=pt,DC=biz", username, password,
                    AuthenticationTypes.Secure))
            {
                var searcher = new DirectorySearcher(entry) {Filter = "sAMAccountName=Bank.Members"};
    
                searcher.PropertiesToLoad.Add("distinguishedName");
                try
                {
                    var sr = searcher.FindOne();
                    var name = sr.Properties["distinguishedName"][0].ToString();
                    result = true;
                }
                catch (Exception exception)
                {
    
    
                }
            }
    
            return result;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-30
      • 2023-03-26
      相关资源
      最近更新 更多