c# - 使用 DirectoryEntry 进行 LDAP 身份验证

标签 c# ldap authentication

我们使用以下 DirectoryEntry 构造函数对 AD 上的用户进行身份验证:

new DirectoryEntry(path, domainName + "\\" + UserName, Password);

在更改域 Controller 之前它一直工作正常。

现在要使其正常工作,我们必须使用:

new DirectoryEntry(path,  UserName, Password);

谁能解释一下区别以及为什么第二种方法现在有效而第一种方法不起作用?

注意:我不确定,但我认为域功能级别从 Server 2003 提升到 Server 2008。这有区别吗?

最佳答案

我不知道为什么这曾经有效:-),因此我无法真正解释为什么其他选项现在有效......

如果您使用 .NET 3.5,则可以使用 System.DirectoryServices.AccountManagement 命名空间并轻松验证您的凭据:

// create a "principal context" - e.g. your domain (could be machine, too)
using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, "YOURDOMAIN"))
{
    // validate the credentials
    bool isValid = pc.ValidateCredentials("myuser", "mypassword")
}

它很简单,很可靠,它是 100% C# 托管代码 - 您还能要求什么呢? :-)

关于c# - 使用 DirectoryEntry 进行 LDAP 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3382815/

相关文章:

c# - 列表不会显示其内容

c# - Cosmos 操作系统问题

java - 检查 LDAP 连接 (Java)

SVN + SASL + ActiveDirectory : How to

android - Ionic View Google 登录弹出窗口在 Firebase 2 中有效,但在 Firebase 3 中无效(在浏览器中有效)

c# - 来自 .NET 的 Windows Mobile API 调用 - 什么是 dll 以及什么是枚举值

C# bit shift : is this behavior in the spec, 是一个错误,还是偶然的?

ldap - 如何在ldap中存储日期?

CakePHP - 验证以保存用户上次登录时间

iphone - 如何开发具有登录功能的基于 TabBar 的应用程序?