我需要通過檢查指定域中是否存在這樣的用戶名來驗證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