1

我試圖搜索我的組織Active Directory for users。根據名字,姓氏和顯示名稱在Active Directory中搜索用戶

如果名字姓氏 DisplayName的一個特定的字符串值相匹配,它應該返回的用戶。

我的代碼:

// create your domain context 
PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 

UserPrincipal qbeUser = new UserPrincipal(ctx); 
qbeUser.GivenName = "Ramesh*"; 
// qbeUser.Surname = "Ramesh*"; 
// qbeUser.DisplayName= "Ramesh*";  

PrincipalSearcher srch = new PrincipalSearcher(qbeUser); 

// find all matches 
foreach(var found in srch.FindAll()) 
{ 
    // 
} 

的問題是,我可以只由一個過濾器來搜索。

我能夠與過濾器,但不是或。是否有任何解決方案可用?

+1

請參閱[此問題的可能解決方案](http://stackoverflow.com/questions/3195124/ambiguous-name-resolution-anr-ma-equivalent-in-net-3-5-directoryservices-ac) - 使用'UserPrincipal'的可擴展性來訪問'anr'屬性(模糊名稱解析),它允許在多個與名稱相關的屬性中搜索 –

+0

@marc_s:感謝您的解決方案。它工作正常。你可以發佈這個答案。所以我可以接受它? –

回答

2

See a possible solution for this issue in this other SO question

您將需要使用UserPrincipal的擴展性來創建子類,以便訪問允許一次搜索多個與名稱相關的屬性的anr屬性(anr =模糊名稱解析)。

+0

此鏈接(http://msdn.microsoft.com/en-us/library/cc223243.aspx)幫助我找到更多關於不明確名稱解析(ANR)的信息。 –

相關問題