-1

这是我的代码:

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();

不返回正确的值。

请帮我

4

2 回答 2

0

我的问题解决:

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;
    }
于 2013-11-06T05:52:22.500 回答
0

只是一个想法,但您不需要像这样设置价值

var PathDic = sr.Properties["distinguishedName"][0].Value.ToString();
于 2013-11-05T16:58:17.637 回答