ContextType.ApplicationDirectory 处的 AD LDS ValidateCredentials 无法进行身份验证
我正在尝试在我的 MVC 应用程序中使用 AD LDS 进行用户身份验证。我已经设法编写了一些代码,允许我创建/编辑/删除用户和组,但我似乎无法对它们进行身份验证。这是我的示例代码:
using( var context = new PrincipalContext(ContextType.ApplicationDirectory, "Lenovo_T61-LapT",
"CN=Kontrahenci,DC=TestApp,DC=local"))
{
var userName = "avg.joe";
var email = "[email protected]";
var password = "123456";
var user = new UserPrincipal(context)
{
Name = userName,
EmailAddress = email
};
user.SetPassword(password);
user.Save();
if (context.ValidateCredentials(userName , password, ContextOptions.SimpleBind))
Console.WriteLine("Hooray!");
user.Dispose();
}
不幸的是,这永远不会到达“Writeline”,仅给出密码或用户名不正确的错误。
我尝试过 ContextOptions 但没有任何运气。
有什么想法吗?
I'm trying to use AD LDS for user authentication in my MVC app. I've managed to write some code that allows me to create/edit/delete users and groups, but i can't seem to authenticate them. Here is my sample code:
using( var context = new PrincipalContext(ContextType.ApplicationDirectory, "Lenovo_T61-LapT",
"CN=Kontrahenci,DC=TestApp,DC=local"))
{
var userName = "avg.joe";
var email = "[email protected]";
var password = "123456";
var user = new UserPrincipal(context)
{
Name = userName,
EmailAddress = email
};
user.SetPassword(password);
user.Save();
if (context.ValidateCredentials(userName , password, ContextOptions.SimpleBind))
Console.WriteLine("Hooray!");
user.Dispose();
}
Unfortunately this never gets to "Writeline" giving only an error that either the password or username are incorrect.
I've played around with ContextOptions but without any luck.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我找到了在类似问题上发布的解决方案。
我所做的并且对我有用的是,在调用 ValidateCredentials 时,我稍微修改了用户名:
希望这会有所帮助。
So I've found the solution which I posted on a similar question.
What I did, and works for me, is when calling ValidateCredentials I modified the username a bit:
Hope this helps.