我需要通过检查指定域中是否存在这样的用户名来验证LDAP用户。对于此我使用此代码 -Active Directory登录 - DirectoryEntry不一致的异常
DirectoryEntry entry = new DirectoryEntry("LDAP://" + strDomainController);
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "SAMAccountName=" + strUserName;
SearchResult result = searcher.FindOne();
return (result != null) ? true : false;
这是一个类库,我intened引用和使用无论我需要在我的项目此功能的方法。
为了测试这个,我创建了一个简单的测试应用程序。测试发生这样的 -
Console.WriteLine(MyClassLib.MyValidateUserMethod("UserName", "Domain",ref strError).ToString());
我现在面临的问题是,这工作得很好,当我和我的testapp,但在我的项目进行测试,当我尝试用同样的方法用相同的凭据 - 在DirectoryEntry
对象抛出"System.DirectoryServices.DirectoryServicesCOMException"
异常,并且search.Filter
失败并抛出ex = {“登录失败:未知用户名或错误密码。\ r \ n”}异常。
我试过模拟,但没有帮助。不知怎的,同样的方法在mytestapp中工作正常,并且在我的项目中不起作用。这两个应用程序都在我的本地开发机器中。我错过了什么?有任何想法吗?
你使用模拟,还是当前的Windows用户? – 2010-05-21 14:57:53
我正在使用模拟。 – pavanred 2010-05-21 18:33:40