DirectoryEntry DirEntry = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.None);
DirectorySearcher search = new DirectorySearcher(DirEntry);
search.Filter = String.Format("(SAMAccountName={0})", "my_login_name");
search.PropertiesToLoad.Add("cn");
SearchResult result1 = search.FindOne();
myDataTable Users = new myDataTable();
DataRow User;
foreach (SearchResult i in search.FindAll())
{
DirectoryEntry CurrentDirEntry;
User = Users.NewUserRow();
CurrentDirEntry = i.GetDirectoryEntry();
User.FirstName = (string)CurrentDirEntry.Properties["givenname"].Value;
User.LastName = (string)CurrentDirEntry.Properties["sn"].Value;
User.UserName = (string)CurrentDirEntry.Properties["sAMAccountName"].Value;
User.Email = (string)CurrentDirEntry.Properties["mail"].Value;
Users.AddUserRow(User);
}
我試圖從Active Directory讀取一些屬性但試圖返回讀取從Active Directory中的登錄名空
sAMAccountName賦
值始終返回空值,我想知道爲什麼這是如此,因爲它被匹配在搜索過濾器。它可能與訪問權限有關嗎?
我想返回名字,姓氏,電子郵件和登錄名。我收到除登錄名之外的其他屬性。
間距實際上是一個錯字,現在糾正。 – StackTrace 2015-02-09 09:08:43