Active Directory连接

时间:2014-08-01 06:11:11

标签: c# .net active-directory

我需要一点帮助。我是活动目录的新手。我想用c#连接我的活动目录。这是我写的示例代码。

 public void GetConnection()
    {
        var username = "xxxx";
        var domain = "xxxx";
        var password = "xxxx";
        var path = "LDAP://xxxx/CN=xx";

        DirectoryEntry de = new DirectoryEntry(sDomain + "/" + sDefaultOU, sUsername, sServicePassword, AuthenticationTypes.ServerBind);
        DirectorySearcher ds = new DirectorySearcher(de);
        //Include subtrees
        ds.SearchScope = System.DirectoryServices.Protocols.SearchScope.Subtree;
        ds.Filter = "(&(objectClass=group))";

        //Fetch all results that match the directory entry (domain)

        var sr = ds.FindAll();

        if (sr != null)
        {
            MessageBox.Show("success");
        }
        else
        {
            MessageBox.Show("error");
        }
        }
    }

错误是:

无法隐式转换类型&system.directoryservices.protocols.searchscope'到' system.directoryservices.searchscope'。显式转换退出。

任何人都可以帮助我吗?

0 个答案:

没有答案