C# 如何在未加入Microsoft Active Directory中的域时使用c对ldap进行身份验证#

C# 如何在未加入Microsoft Active Directory中的域时使用c对ldap进行身份验证#,c#,.net,.net-2.0,ldap,C#,.net,.net 2.0,Ldap,由于某些原因,当计算机未加入域时,ldap和目录服务不起作用。来自.net域的错误消息不可用。有人知道需要做什么吗 基本的 domainAndUsername = domain + @"\" + username; entry = new DirectoryEntry(_path, domainAndUsername, pwd); entry.AuthenticationType = FindAuthTypeMicrosoft(authType); 。。。尝试向上述代码提供testdom

由于某些原因,当计算机未加入域时,ldap和目录服务不起作用。来自.net域的错误消息不可用。有人知道需要做什么吗

基本的

 domainAndUsername = domain + @"\" + username;
 entry = new DirectoryEntry(_path, domainAndUsername, pwd);
 entry.AuthenticationType = FindAuthTypeMicrosoft(authType);
。。。尝试向上述代码提供testdomain.com时,在本地登录到计算机时似乎不起作用


即使我可以ping testdomain.com而没有任何问题。有什么不同或问题吗?

目录服务依赖于ActiveDirectory。因此,您需要将计算机添加到域或显式提供域控制器。请注意,域并不意味着来自域名系统的域名。这意味着一个ActiveDirectory域。

这段代码在过去对我很有用(尽管我承认我现在无法测试它):


最困难的部分(无论如何对我来说)是找出“连接字符串”的细节。我通常依赖并帮助我找出正确的值免费版本有点老了,v2.6版,藏在下载区。

我把路径留空了。对不起,我自己的问题

DirectoryEntry entry = new DirectoryEntry("LDAP://server-name/DC=domainContext,DC=com");
entry.Username = @"DOMAIN\account";
entry.Password = "...";
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=user)(sn=Jones))";
SearchResultCollection results = searcher.FindAll();