gpt4 book ai didi

c# - 使用 System.DirectoryService 连接到 OpenDS

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:52 24 4
gpt4 key购买 nike

我一直试图找到一些关于如何使用 .NET 的 LDAP 类型连接到 OpenDS 的教程,但没有成功。任何人都可以向我指出一些文章/教程,其中包含有关将 OpenDS 用作目录服务以及使用 C# 访问和使用它的良好示例。

这是我迄今为止尝试过的方法,但总是出现无效的用户名/密码错误。我被困在需要输入什么凭据,或者我正在尝试做的事情是否有意义。

DirectoryEntry directoryEntry = new DirectoryEntry
{
Path = @"LDAP://SUnnikris-va-d:389/dc=example,dc=com",
Username = "uid=user.0",
Password = "TestPass!",
AuthenticationType = AuthenticationTypes.ServerBind
};

directoryEntry.RefreshCache();

DirectoryEntry newUser = directoryEntry.Children.Add("uid=nuser,ou=People,dc=example,dc=com", "person");
newUser.Properties["objectClass"].Value = new object[] { "top", "person", "organizationalPerson", "inetorgPerson" };
newUser.Properties["uid"].Value = "nuser";
newUser.Properties["givenName"].Value = "new";
newUser.Properties["sn"].Value = "user";
newUser.Properties["cn"].Value = "new user";
newUser.Properties["userPassword"].Value = "nuser";
newUser.CommitChanges();

最佳答案

我猜你的用户名是错误的,你需要输入用户名的完整 ldap 路径,即uid=admin,ou=AdminOU,dc=example,dc=com

您还可以使用 System.DirectoryServices.AccountManagement 来更轻松地实现,请看这里 -> http://anyrest.wordpress.com/2010/06/28/active-directory-c/

关于c# - 使用 System.DirectoryService 连接到 OpenDS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3711879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com