LDAP服务器不可用
我是个新手
尝试使用PrincipalContext
连接到ldap服务器。 我试过这个网站上的所有解决方案都无济于事。
我尝试过的事情:
PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain); PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, "ldap://localhost:389/dc=maxcrc,dc=com"); PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, "maxcrc.com");
所有都给出了相同的结果:
LDAP服务器不可用
只有ContextType.Machine
基本上ContextType.Machine
工作。
不确定我的LDAP服务器是否设置正确:
使用Softerra LDAP浏览器进行测试
从头到尾的任何教程都将非常感谢…
我一直面临同样的问题,我找到了解决方案。
我可以使用以下代码轻松连接:
ADUser_Id = "domainName\username"; //make sure user name has domain name. Password = "xxxx"; var context = new PrincipalContext(ContextType.Domain,"server_address", ADUser_Id,Password); /* server_address = "192.168.15.36"; //don't include ldap in url */
我有类似的问题。 事实certificate,我必须在对象初始化中传递用户名和密码。 请尝试使用如下语句:
PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, "ldap://localhost:389/dc=maxcrc,dc=com", userName, password);
另外,请确保您的用户名中包含域名。
例如,
userName = "mydomainname" + "\" + "john_jacobs"
您可能希望尝试使用本地计算机地址:
ldap://127.0.0.1:389/dc=maxcrc,dc=com
如果这不起作用,我会启动Wireshark,并在尝试通过Softerra连接时捕获端口389上的流量。
在使用LDAP和.Net DirectoryServices时,该错误通常意味着路径的语法或命名约定不正确,或者未指向有效的目录端点。
该错误可能是由于尝试连接为“匿名”而未明确指定它。 默认情况下,所有连接都是可以协商的。 因此,如果你尝试这样的东西,你可以尝试以下方法:
LdapDirectoryIdentifier ldap = new LdapDirectoryIdentifier("My Hostname or IP Address",10389); //10389 might be your non default port LdapConnection connection = new LdapConnection(ldap); connection.AuthType = AuthType.Anonymous;
对PrincipalContext
使用以下构造函数重载:
public PrincipalContext( ContextType contextType, string name, string container )
并将服务器名称与LDAP字符串分开:
PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, "localhost:389", "dc=maxcrc,dc=com");
https://msdn.microsoft.com/en-us/library/bb348316%28v=vs.110%29.aspx
在我的环境中,我不得不仅使用域控制器主机名创建主体上下文,然后单独validation用户凭据。
string domainControllerName = "PDC"; string domainName = "MyDomain"; // leave out the .Local, this is just to use as the prefix for the username if the user left it off or didn't use the principal address notation string username = "TestUser"; string password = "password"; using (var ldap = new PrincipalContext(ContextType.Domain, domainControllerName)) { var usernameToValidate = username; if (!usernameToValidate.Any(c => c == '@' || c == '\')) usernameToValidate = $"{domainName}\{username}"; if (!ldap.ValidateCredentials(username, context.Password, ContextOptions.SimpleBind)) throw new UnauthorizedException(); }
此示例允许用户名的所有这三个变体进行validation:
上述就是C#学习教程:LDAP服务器不可用分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/958764.html