本文介紹了如何使用 C# 按用戶名搜索 Active Directory?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試通過用戶名admin"搜索活動目錄.我知道目錄中存在具有該用戶名的用戶,但搜索一直沒有結果.
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 結束.我很想知道為什么,一定有我遺漏的東西.
userResult always ends up null. I would love to know why, there must be something that I'm missing.
推薦答案
原來userPrincipalName"需要全部小寫(userprincipalname").很高興知道,感謝您的回復.
It turns out that "userPrincipalName" needed to be all lower-case ("userprincipalname"). Good to know, thanks for your responses.
這篇關于如何使用 C# 按用戶名搜索 Active Directory?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!