System.DirectoryServices.AccountManagement 自己引导

发布于 2024-10-31 05:35:36 字数 986 浏览 0 评论 0原文

我正在尝试在 System.DirectoryServices.AccountManagement 命名空间上引导自己,以解决我遇到的另一个问题。在网络中,我想切换广告中的“ChangePasswordOnNextLogon”标志,这个命名空间使它看起来很容易。

因此,我尝试使用与使用 AdMembershipProvider 登录时相同的用户和密码来使用它。

PrincipalContext oPrincipalContext = 
   new PrincipalContext(ContextType.Domain, "10.1.XXX.XXX", "DC=XXXXXXXX,DC=ORG",
                        ContextOptions.SimpleBind, AUserThatWorks, APasswordThatWorks);

UserPrincipal oUserPrincipal = 
    UserPrincipal.FindByIdentity(oPrincipalContext, AdUserName);

// we need to see if they can authenticate before changing password,so we have to turn this off manually. - EWB
oUserPrincipal.RefreshExpiredPassword();

bool b = oPrincipalContext.ValidateCredentials( AdUserName, AdPassword );

if (!b)
   oUserPrincipal.ExpirePasswordNow();

return b;

但是当它到达 FindByIdentity 时,我收到“错误的用户或密码”错误。

由于用户在其他地方工作,我认为它必须是获取主要上下文的其他参数之一。有人给我任何提示吗?我尝试将 LDAP 放在 URL 前面,但连接失败。我很困惑。

谢谢,

卡尔-

I'm trying to bootstrap myself up on the System.DirectoryServices.AccountManagement namespace in order to solve another issue I'm having. In net i want to toggle the "ChangePasswordOnNextLogon" flag in ad and this namespace made it look easy.

So I tried using it with the same users and passwords that I use to login using the AdMembershipProvider.

PrincipalContext oPrincipalContext = 
   new PrincipalContext(ContextType.Domain, "10.1.XXX.XXX", "DC=XXXXXXXX,DC=ORG",
                        ContextOptions.SimpleBind, AUserThatWorks, APasswordThatWorks);

UserPrincipal oUserPrincipal = 
    UserPrincipal.FindByIdentity(oPrincipalContext, AdUserName);

// we need to see if they can authenticate before changing password,so we have to turn this off manually. - EWB
oUserPrincipal.RefreshExpiredPassword();

bool b = oPrincipalContext.ValidateCredentials( AdUserName, AdPassword );

if (!b)
   oUserPrincipal.ExpirePasswordNow();

return b;

But when it gets to FindByIdentity I get a "bad user or password" error.

Since the user works elsewhere, I figure it's gotta be one of the other parameters to get principal context. Anyone got any Hints for me? I tried putting LDAP infront of the URL but then it failed to connect. I'm stumped.

Thanks,

Cal-

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烈酒灼喉 2024-11-07 05:35:36

尝试简化您的PrincipalContext行:

PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, "XXXXXX.org", AUserThatWorks, PasswordThatWorks);

这假设您的域是XXXXXXX.org。您还可以尝试将您的域名放在用户名前面:“XXXXXX.org\用户名”。

Try simplifying your PrincipalContext line:

PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, "XXXXXX.org", AUserThatWorks, PasswordThatWorks);

This assumes your domain is XXXXXXX.org. You can also try putting your domain in front of your username: "XXXXXX.org\username".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文