简体   繁体   English

连接到C#.NET中的Active Directory服务器的问题

[英]problem connecting to Active Directory server in C# .NET

I'm currently writing some software in C# which needs to connect to an AD server and get some user details. 我目前正在用C#编写一些软件,需要连接到AD服务器并获取一些用户详细信息。 When I connect using the code below it works against most AD servers that I connect to but there are a couple where it fails with an error of "Logon failure: unknown user name or bad password.". 当我使用下面的代码进行连接时,它可以对付我连接的大多数AD服务器,但有一些地方失败并出现“登录失败:未知用户名或密码错误”的错误。 The server name / credentials I'm using are definately correct as I've tested them with an LDAP Browser and the AD server is using standard security (port 389 etc). 我正在使用的服务器名称/凭证肯定是正确的,因为我使用LDAP浏览器测试它们并且AD服务器使用标准安全性(端口389等)。 Can anyone offer any advice? 有人可以提供任何建议吗?

Cheers 干杯

Tim 蒂姆

DirectoryEntry d = new DirectoryEntry("LDAP://" + domain, admin_username, admin_password);

try
{
   object x = d.NativeObject;
}
catch
{
   throw;
}

I've had similar issues programming .net / AD in the past. 编程.net / AD过去曾遇到过类似的问题。 One thing I found useful is using an LDAP viewer to see if I can connect to certain servers, etc. In this way, I can at least determine if it is a .NET error (perhaps my code), a credential error, etc. 我发现有用的一件事是使用LDAP查看器来查看我是否可以连接到某些服务器等。这样,我至少可以确定它是否是.NET错误(可能是我的代码),凭据错误等。

I use the free/lite version of Softerra's LDAP viewer ( http://www.ldapbrowser.com/download.htm ) although I'm sure there are many others to choose from out there. 我使用了Softerra的LDAP查看器的免费/ lite版本( http://www.ldapbrowser.com/download.htm ),虽然我确信还有很多其他人可供选择。 If you try the one listed here, make sure to download the 'LDAP browser' and not 'LDAP Administrator'. 如果您尝试此处列出的那个,请确保下载“LDAP浏览器”而不是“LDAP管理员”。 The browser is the free one. 浏览器是免费的。

Try connecting to the same LDAP path you're having trouble with in code, using a LDAP browser/viewer. 尝试使用LDAP浏览器/查看器连接到您在代码中遇到问题的同一LDAP路径。 This will at least as step one determine if it is a .NET/code issue or not. 至少在第一步确定它是否是.NET /代码问题时。 If you can't connect via the browser, it can be helpful to play around with the connection options, such as port, domain (FQDN), etc. 如果无法通过浏览器进行连接,则可以使用连接选项,例如端口,域(FQDN)等。

Hope this might help narrow things down. 希望这可能有助于缩小范围。

Active Directory allows at least three different logon name styles: Active Directory至少允许三种不同的登录名称样式:

  1. LDAP - ie LDAP DN. LDAP - 即LDAP DN。 For example: cn=JohnS, ou=Users, dc=example, dc=com 例如:cn = JohnS,ou = Users,dc = example,dc = com
  2. NTLM. NTLM。 For example: EXAMPLE\\JohnS 例如:EXAMPLE \\ JohnS
  3. Kerberos principal name: For example: johns@example.com Kerberos主体名称:例如:johns@example.com

However, you cannot login with just JohnS like you do with Windows box. 但是,您不能像使用Windows框一样只使用JohnS登录。 It's a very common mistake. 这是一个非常常见的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM