C# 操作 Active Directory 报出"登录失败: 未知的用户名或错误密码。"

jasonf 2009-04-24 09:57:19
DirectoryEntry entry = new DirectoryEntry(ADPath, userName, password, AuthenticationTypes.None);
return entry;

用以上代码构造出一个entry对象,再利用entry构造出一个DirectorySearcher,利用其搜索出一个DirectoryEntry,但在访问DirectoryEntry对象的Properties属性时,报
异常详细信息: System.DirectoryServices.DirectoryServicesCOMException: 登录失败: 未知的用户名或错误密码。

DirectoryEntry de = GetDirectoryEntryByAccount(sAMAccountName);
if (de != null)
{
string commonName = de.Properties["cn"][0].ToString();//主要出错是这段代码〈〈〈〈〈〈=====
}

以上的ADPath, userName, password 均在LDP.EXE中使用没有问题,但是代码实现中就有问题,不知是哪方面的问题。请指教!!!
...全文
1455 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Reaforstar 2010-12-23
  • 打赏
  • 举报
回复
一样的问题,是不是对于每次用DirectoryEntry对象都要用用户名和密码去构造,这块不知道怎么搞的!!
pyonline 2010-08-05
  • 打赏
  • 举报
回复
一样的问题啊,还有人解决了?
yirantaoqi 2010-07-25
  • 打赏
  • 举报
回复
我也有这样的问题
wayne0207 2010-07-17
  • 打赏
  • 举报
回复
楼主,问题解决了没?出现跟你一样的情况了撒。
jasonf 2009-04-29
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 jsntzll 的回复:]
访问我的博客 程序员日记http://www.ideaext.com
[/Quote]

BS....
jasonf 2009-04-28
  • 打赏
  • 举报
回复
///
///获得DirectoryEntry对象实例,以管理员登陆AD
///
///
private static DirectoryEntry GetDirectoryObject()
{
DirectoryEntry entry = new DirectoryEntry(ADPath, ADUser, ADPassword, AuthenticationTypes.ServerBind);
return entry;
}


其实这个方法先前就有试过,刚才再重新试了下,依然出现以下错误."登录失败: 未知的用户名或错误密码"
jasonf 2009-04-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 whoami333 的回复:]
LDAP://...

WinNT//...

???
[/Quote]

正如 bluebrother 兄所说
ADPath = "LDAP://这种";
ADUser = "domain/userName";
使用的是这个,而且在LDP.EXE中是可以登陆的....
feifeiyiwen 2009-04-28
  • 打赏
  • 举报
回复
以前也遇到过,但记不清怎么解决的了
bluebrother 2009-04-28
  • 打赏
  • 举报
回复

ADPath = "LDAP://这种";
ADUser = "domain/userName";
whoami333 2009-04-28
  • 打赏
  • 举报
回复
LDAP://...

WinNT//...

???
freewind0521 2009-04-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 whoami333 的回复:]
AuthenticationTypes.ServerBind试一下。
[/Quote]
up
whoami333 2009-04-24
  • 打赏
  • 举报
回复
AuthenticationTypes.ServerBind试一下。

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧