久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

檢索用戶的自定義 Active Directory 屬性

Retrieving custom Active Directory properties of users(檢索用戶的自定義 Active Directory 屬性)
本文介紹了檢索用戶的自定義 Active Directory 屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我一直在嘗試檢索為我們的 Active Directory 用戶設(shè)置的兩個自定義屬性,但似乎我一直在獲取一個恒定的屬性列表(在 2 個不同的 AD 服務(wù)器上測試)

I've been trying to retrieve two custom properties that are set on our Active Directory users, but it seems like I keep getting a constant list of Properties (tested over 2 different AD servers)

假設(shè)我試圖獲取的屬性是 prop1prop2,我在下面的代碼中做錯了什么:

Assuming the properties I'm trying to fetch are prop1 and prop2, What am I doing wrong in the following code:

        List<String> nProps = new List<string>();

        DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://DOM");
        foreach (DirectoryEntry child in directoryEntry.Children)
        {
            // No filtering; ignore schemes that are not User schemes
            if (child.SchemaClassName == "User")
            {
                foreach (var sVar in child.Properties.PropertyNames)
                    nProps.Add(sVar.ToString());

                break;
            }
        }

nProps 不包含我的任何自定義屬性(不是 prop1 也不是 prop2)

nProps does not contain ANY of my custom properties (not prop1 nor prop2)

(它確實包含其他屬性,例如 BadPasswordAttempts、用戶名等)

(it does contain other properties, like BadPasswordAttempts, Username, etc)

有什么想法嗎?

推薦答案

你確定你的屬性設(shè)置了嗎?如果未設(shè)置它們,它們將不會被列為屬性.

如果您正在尋找特定的屬性,我建議您使用 目錄搜索器

以下示例獲取給定用戶的公司屬性.請注意,您首先驗證該屬性是否存在,然后提取它.

Are you sure your properties are set? if they are not set, they are not gonna be listed as properties.

If you're looking for specific properties, I'd recommend you to use DirectorySearcher

The following example is getting the company property of a given user. Note that you verify if the property exists first, then you extract it.

DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://DOM");

//Create a searcher on your DirectoryEntry
DirectorySearcher adSearch= new DirectorySearcher(directoryEntry);
adSearch.SearchScope = SearchScope.Subtree;    //Look into all subtree during the search
adSearch.Filter = "(&(ObjectClass=user)(sAMAccountName="+ username +"))";    //Filter information, here i'm looking at a user with given username
SearchResult sResul = adSearch.FindOne();       //username is unique, so I want to find only one

if (sResult.Properties.Contains("company"))     //Let's say I want the company name (any property here)
{
    string companyName = sResult.Properties["company"][0].ToString();    //Get the property info
}

這篇關(guān)于檢索用戶的自定義 Active Directory 屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應(yīng)該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設(shè)置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調(diào)用)
主站蜘蛛池模板: 欧美精品久久 | 精品一区二区三区免费视频 | 午夜免费电影 | 91.色| 综合精品久久久 | 中文字幕一区二区三区精彩视频 | 国产精品视频网 | 99re国产| 久久av一区 | 高清一区二区三区 | 91在线中文字幕 | 成人在线播放 | 黄视频网址| 国产a级毛片 | 亚洲一二三区在线观看 | 中文字幕免费在线 | 51ⅴ精品国产91久久久久久 | 亚洲福利一区二区 | 欧美精品在线免费观看 | 成年人精品视频在线观看 | 古典武侠第一页久久777 | 成人免费视频观看 | 亚洲视频精品 | 日韩成人免费av | 最新91在线 | 国产成人精品一区二 | 亚洲一区二区三区在线播放 | 日韩国产中文字幕 | 精品不卡 | 午夜伦理影院 | 特黄色一级毛片 | 一本一道久久a久久精品综合蜜臀 | 成人欧美一区二区三区在线观看 | 无吗视频 | 亚洲 欧美 精品 | 最新免费视频 | 91精品久久久| 国产乱性 | 日韩欧美成人精品 | av中文天堂| 午夜免费在线 |