System.DirectoryServices.AccountManagement 自己引导
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试简化您的PrincipalContext行:
这假设您的域是XXXXXXX.org。您还可以尝试将您的域名放在用户名前面:“XXXXXX.org\用户名”。
Try simplifying your PrincipalContext line:
This assumes your domain is XXXXXXX.org. You can also try putting your domain in front of your username: "XXXXXX.org\username".