欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

关于c#:LDAP服务器不可用 The LDAP server is unavailable 有大用

我是这个的新手。

尝试使用PrincipalContext连接到ldap服务器。我已经尝试了该站点上的所有解决方案,但均无济于事。

我尝试过的事情:

1
2
3
4
5
6
7
8
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 server not available

只有ContextType.Machine可以正常工作。确保我的LDAP服务器设置正确:

  • 主机:localhost

  • 端口:389

  • 基本DN:dc = maxcrc,dc = com

  • URL:ldap:// localhost:389 / dc = maxcrc,dc = com

使用Softerra LDAP浏览器进行测试

从头到尾的任何教程都将不胜感激...


  • 这听起来可能很愚蠢,但请尝试使用

    LDAP://

    而不是

    LDAP://

    ,因为我知道过去这对我来说是固定连接

  • 没有同样的结果。但是谢谢

  • 您可以使用任何标准的AD工具连接到LDAP服务器吗?

  • @mellamokb,如果通过标准的AD工具表示DirectoryEntry,则为是。我已经尝试过:DirectoryEntry rootDSE = new DirectoryEntry(\\\\" LDAP:// RootDSE \\\\");






我遇到了同样的问题,并且找到了解决方案。

我能够使用以下代码轻松连接:

1
2
3
4
 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 */


  • 指定服务器主机名对我有用。我可以将没有域的用户用于

    ADUser_Id

    。好帖子。




我有类似的问题。原来,我必须在对象初始化时传递用户名和密码。请尝试使用如下语句:

1
2
3
4
5
PrincipalContext insPrincipalContext =
new PrincipalContext(ContextType.Domain,
"ldap://localhost:389/dc=maxcrc,dc=com",
userName,
password);

也请确保您的用户名中包含域。

例如,

1
userName ="mydomainname" +"\" +"john_jacobs"


  • 对我来说,它按照您的建议将凭据直接传递到对象初始化中。




PrincipalContext使用以下构造函数重载:

1
2
3
4
5
public PrincipalContext(
    ContextType contextType,
    string name,
    string container
)

,并将服务器名称与LDAP字符串分开:

1
2
PrincipalContext insPrincipalContext =
   new PrincipalContext(ContextType.Domain,"localhost:389","dc=maxcrc,dc=com");

https://msdn.microsoft.com / en-us / library / bb348316(v = vs.110).aspx


在我的环境中,我必须仅使用域控制器主机名创建主体上下文,然后分别验证用户凭据。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 == '\\\'))
            usernameToValidate = $"{domainName}\\\\{username}";

    if (!ldap.ValidateCredentials(username, context.Password, ContextOptions.SimpleBind))
        throw new UnauthorizedException();
}



This example allows for all three of these variations to the username to validate:


该错误可能是由于尝试使用" Anonymous "进行连接而未明确指定。默认情况下,所有连接都是可协商的。因此,如果尝试类似的操作,则可以尝试以下操作:

1
2
3
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;

您可能想改用您的本地计算机地址:

1
ldap://127.0.0.1:389/dc=maxcrc,dc=com

如果这不起作用,我将启动Wireshark,并在尝试时捕获端口389上的流量通过Softerra连接。

在我使用LDAP和.Net DirectoryServices的时候,该错误通常表示路径的语法或命名约定不正确,或者未指向有效的目录端点。 >


来自  https://www.codenong.com/14480258/


普通分类: