本文介紹了如何使用 C# 按用戶名搜索 Active Directory?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我正在嘗試通過(guò)用戶名admin"搜索活動(dòng)目錄.我知道目錄中存在具有該用戶名的用戶,但搜索一直沒(méi)有結(jié)果.
I'm trying to search active directory by the username 'admin'. I know for a fact that there is a user with that username in the directory, but the search keeps coming back with nothing.
var attributeName = "userPrincipalName";
var searchString = "admin"
var ent = new DirectoryEntry("LDAP://"dc=corp,dc=contoso,dc=com")
var mySearcher = new DirectorySearcher(ent);
mySearcher.Filter = string.Format("(&(objectClass=user)({0}={1}))", attributeName, searchString);
var userResult = mySearcher.FindOne();
userResult 總是以 null 結(jié)束.我很想知道為什么,一定有我遺漏的東西.
userResult always ends up null. I would love to know why, there must be something that I'm missing.
推薦答案
原來(lái)userPrincipalName"需要全部小寫(xiě)(userprincipalname").很高興知道,感謝您的回復(fù).
It turns out that "userPrincipalName" needed to be all lower-case ("userprincipalname"). Good to know, thanks for your responses.
這篇關(guān)于如何使用 C# 按用戶名搜索 Active Directory?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!