Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用管理员凭据访问LDAP用户_C#_.net_Ldap - Fatal编程技术网

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

C# 如何使用管理员凭据访问LDAP用户,c#,.net,ldap,C#,.net,Ldap,我必须在我的应用程序中创建用户,但在此之前,我需要在Active Directory中验证用户,还需要使用用户/密码进行登录验证,但当我运行下面的代码时,它会给出服务器不可用的信息 try { LdapConnection connection = new LdapConnection(ConfigurationManager.AppSettings["ADDomain"]); Console.WriteLine("Enter LDAP User Name:"); string

我必须在我的应用程序中创建用户,但在此之前,我需要在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[“AddDomain”]是ldap路径ldap://IP:389/ou=Service 账户,DC=DEVDD,DC=ABC,DC=Local?sAMAccountName?sub“

在.bind()行出现服务器不可用的错误。

说明参数应为:

指定服务器的字符串,可以是域名、LDAP服务器名称或表示LDAP服务器IP地址的虚线字符串。或者,此参数还可以包括端口号,该端口号由冒号(:)与字符串的右端分隔

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