我正在使用C#应用程序进行身份验证并检查位于Window 2008 64位服务器上的Active Directory用户。如何检查LDAP用户是否存在/活动?
我能够提供的用户名和使用下面的代码密码时,成功地验证用户:我则domainName值rootforest.com和我的用户名是admin6
UserPrincipal usr;
PrincipalContext ad;
//Enter Active Directory settings
ad = new PrincipalContext(ContextType.Domain, domainName,usrName,pswd);
//search user
usr = new UserPrincipal(ad);
usr.SamAccountName = usrName;
PrincipalSearcher search = new PrincipalSearcher(usr);
usr = (UserPrincipal)search.FindOne();
search.Dispose();
在我想另一个函数检查用户'admin6'是否存在,并且我没有密码,但是当我检查它时,该函数继续抛出“登录失败:unkoown用户名或错误密码。\ r \ n”。我使用的代码几乎与上述相同,除了这行:
//Enter Active Directory settings
ad = new PrincipalContext(ContextType.Domain, domainName);
有了这个不工作,我已经尝试过其他的代码,我在网上找到,但他们都给予我同样的错误。我开始认为这可能是我如何设置我的Active Directory域?
下面的图片是怎么我的域名看起来:
https://picasaweb.google.com/100922945973553878191/ActiveDirectory?authuser=0&feat=directlink
谁能帮助我?我一直坚持这个问题的最后一天左右,现在我似乎无法找出原因。如果您有一些代码,我可以尝试它会很好
我在一个窗口机器上,所以我下载了LDAPSoft AD管理工具来检查我的连接,我可以看到我的distinguishedName到账户'admin6'是CN = admin6,CN = Users,DC = rootforest,DC = com。我尝试在我的代码中使用if(DirectoryEntry.Exists(“LDAP:// CN = admin6,CN = Users,DC = rootforest,DC = com))或if(DirectoryEntry.Exists(”LDAP:// DC = rootforest,DC = com))但仍然没有运气 – Fylix 2012-03-08 19:44:39