adlds文件服务器,c#-使用PrincipalContext和ADLDS LDAP服务器不可用

我们将ADLDS用于我们的用户管理和身份验证.我们可以成功查询实例而不会出现问题.但是,如果未设置密码,尝试执行诸如SetPassword之类的操作将失败,甚至尝试创建新用户,该操作也会失败.我可以成功更新用户,只要它不是我要更新的密码即可.我读过很多与此相关的文章,但没有找到解决方法.张贴文章,看看我是否可以对此问题有新的见解,谢谢您的投入.

ContextType ctxType = ContextType.ApplicationDirectory;

string server = "myadldsserver.com";

string usersCN = "CN=Users,..."; // container where users reside

ContextOptions ctxOpts = ContextOptions.SimpleBind;

string uname = "myuser";

string pswrd = "mypass";

using(var ctx = new PrincipalContext(ctxType, server, usersCN, ctxOpts, uname, pswrd)

using(var newUser = new UserPrincipal(ctx)) {

newUser.Name = "newusername";

newUser.Enabled = true;

newUser.UserPrincipalName = "newusername";

newUser.Save();

newUser.SetPassword("newuserpassword");

}

错误1

如果我尝试创建一个新的UserPrincipal并在不像上面的示例那样设置密码的情况下调用Save时遇到的第一个问题,我会遇到异常违反约束的情况.带有InnerException扩展消息0000052D:AtrErr:DSID-033807D7,#1:0:0000052D:DSID-033807D7,问题1005(CONSTRAINT_ATT_TYPE),数据2246,Att 9005a(unicodePwd)

由于这个错误,我尝试在调用Save之前移动SetPassword以及其他在线找到的方法,例如从UserPrincipal获取DirectoryEntry并尝试调用SetPassword,但遇到了另一个错误.

错误2

在调用UserPrincipal.Save之前先调用SetPassword,然后调用save会导致错误在缓存中找不到目录属性.

请注意,如果我尝试调用ResetPassword或获取DirectoryEntry并调用Invoke(“ SetPassword” …,也会发生相同的错误.

错误3

根据我的研究,大多数人似乎表明这可能与需要使用安全连接访问AD LDS有关.因此,我将服务器更改为包括636字符串服务器=“ myadldsserver.com:636”的端口,并将ContextOptions更改为ContextOptions.SimpleBind | ContextOptions.SecureSocketLayer.

在构造PrincipalContext时进行这些更改时,出现以下异常无法联系服务器.内部异常为LDAP服务器不可用.HResult为-2146233087

JAVA和LDP

为了为此增加一些背景,我们确实在旧的Java应用程序中编写了类似的代码.我们正在尝试将此逻辑中的某些移植到C#中的.NET端. Java中的代码使用Java密钥库,该密钥库包含在AD LDS服务器上生成的证书.使用SSL端口,Java应用程序当然没有问题.我们知道服务器似乎配置正确,这只是如何从.NET端访问它的问题.

.NET端是否有等效项,例如Java中的密钥库?我们知道可以与服务器建立SSL连接.我们也使用LDP验证了这一点.

目标

>能够创建新用户并在创建过程中设置其密码

>能够为用户重置密码或更改密码

>从.NET安全地连接到我们的AD LDS实例

解决方法:

您是否尝试过使用Microsoft管理控制台导入证书?

两种安装证书的方法

要么

Open a cmd.exe console and type “MMC”

File > Add/Remove Snap-In…

Select Certificates, click Add

Choose Computer Account and Local Computer when prompted, then OK…

Certificates should now be showing under Console Root

Certificates > Trusted Root Certification Authorities > Certificates > (right-click) > All Tasks > Import Certificate…

Find the certificate you want to import, click Next and choose defaults (Trusted Root Certification Authorities should already be

selected)

Click Next, Finish

(要么)

Simply double-click on the .cer file for the certificate in Windows

Explorer, click Install Certificate… > Next > select the option to

“Place all certificates in following store” > Browse… > Select

Trusted Root Certification Authorities. Continue with next until done.

此时,您的证书已安装,并且您应该能够与ADLDS服务器安全地通信.

标签:directoryservices,adlds,userprincipal,principalcontext,c

来源: https://codeday.me/bug/20191111/2019502.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值