我必须在我的应用程序中创建用户,但在此之前,我需要在Active Directory中验证用户,还需要使用登录时的用户名/密码来验证它,但当我运行下面的代码时,它给出的服务器不可用。
try {
LdapConnection connection = new LdapConnection(ConfigurationManager.AppSettings["ADDomain"]);
Console.WriteLine("Enter LDAP User Name:");
string LDAPUser = Console.ReadLine();
Console.WriteLine("Enter LDAP User Password:");
string LDAPPass = Console.ReadLine();
NetworkCredential credential = new NetworkCredential(LDAPUser, LDAPPass);
connection.Credential = credential;
connection.Bind();
Console.WriteLine("logged in");
string c = Console.ReadLine();
} catch (LdapException lexc) {
String error = lexc.ServerErrorMessage;
Console.WriteLine(lexc);
string ads = Console.ReadLine();
} catch (Exception exc) {
Console.WriteLine(exc);
string ss = Console.ReadLine();
}
string s = Console.ReadLine();ConfigurationManager.AppSettings"ADDomain“是ldap路径”ldap://IP:389/ou=服务帐户,DC=DEVDD,DC=ABC,DC=Local?sAMAccountName?sub“
在.bind()行上出现错误:服务器不可用。
发布于 2019-09-10 23:33:32
documentation for the LdapConnnection constructor表示该参数应为:
LDAP指定服务器的字符串,可以是域名、
服务器名称或表示LDAP服务器的IP地址的点分字符串。或者,此参数还可以包括端口号,该端口号与字符串的右端之间用冒号(:)分隔。
所以它应该只是服务器,而不是LDAP路径。您可以将您的ADDomain更改为服务器IP (或域名)。端口389是默认端口,因此除非端口不是389,否则不需要包含该端口。
https://stackoverflow.com/questions/57843772
复制相似问题