首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用管理员凭据访问LDAP用户

问如何使用管理员凭据访问LDAP用户
EN

Stack Overflow用户
提问于 2019-09-09 00:34:30
回答 1查看 32关注 0票数 0

我必须在我的应用程序中创建用户,但在此之前,我需要在Active Directory中验证用户,还需要使用登录时的用户名/密码来验证它,但当我运行下面的代码时,它给出的服务器不可用。

代码语言:javascript
复制
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()行上出现错误:服务器不可用。

EN

回答 1

Stack Overflow用户

发布于 2019-09-10 23:33:32

documentation for the LdapConnnection constructor表示该参数应为:

LDAP指定服务器的字符串,可以是域名、

服务器名称或表示LDAP服务器的IP地址的点分字符串。或者,此参数还可以包括端口号,该端口号与字符串的右端之间用冒号(:)分隔。

所以它应该只是服务器,而不是LDAP路径。您可以将您的ADDomain更改为服务器IP (或域名)。端口389是默认端口,因此除非端口不是389,否则不需要包含该端口。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57843772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档