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

從 UserPrincipal 對象中獲取 nETBIOSName

Get nETBIOSName from a UserPrincipal object(從 UserPrincipal 對象中獲取 nETBIOSName)
本文介紹了從 UserPrincipal 對象中獲取 nETBIOSName的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在使用 .Net 庫的 System.DirectoryServices.AccountManagement 部分來連接到 ActiveDirectory.

I am using the System.DirectoryServices.AccountManagement part of the .Net library to interface into ActiveDirectory.

在 GroupPrincipal 對象上調(diào)用 GetMembers() 并過濾結(jié)果后,我現(xiàn)在有一組 UserPrincipal 對象

Having called GetMembers() on a GroupPrincipal object and filter the results, I now have a collection of UserPrincipal objects

GroupPrincipal myGroup;  // population of this object omitted here 

foreach (UserPrincipal user in myGroup.GetMembers(false).OfType<UserPrincipal>())
{
    Console.WriteLine(user.SamAccountName);
}

上面的代碼示例將打印出像TestUser1"這樣的用戶名.我需要將這些與來自DOMAINTestUser1"格式的另一個應(yīng)用程序的列表進行比較.

The above code sample will print out usernames like "TestUser1". I need to compare these to a list coming from another application in "DOMAINTestUser1" format.

如何從 UserPrincipal 對象中獲取DOMAIN"部分?

How do I get the "DOMAIN" part from the UserPrincipal object?

我不能只附加一個已知域名,因為涉及多個域,我需要區(qū)分 DOMAIN1TestUser1 和 DOMAIN2TestUser2.

I can't just append a known domain name as there are multiple domains involved and I need to differentiate DOMAIN1TestUser1 and DOMAIN2TestUser2.

推薦答案

你有兩個我能想到的選擇.

You have two choices that I can think of.

  1. 解析或獲取name@fully.qualified.domain.name右側(cè)的所有內(nèi)容;
  2. 使用 System.DirectoryServices 命名空間.
  1. Parse, or take everything that is on, the right of name@fully.qualified.domain.name;
  2. Use the System.DirectoryServices namespace.

我不了解 UserPrincipal,也不了解 GroupPrincipal.另一方面,我知道一種可行的方法來實現(xiàn)你想要的.

I don't know about UserPrincipal, neither do I about GroupPrincipal. On the other hand, I know of a working way to achive to what you want.

[TestCase("LDAP://fully.qualified.domain.name", "TestUser1")] 
public void GetNetBiosName(string ldapUrl, string login)
    string netBiosName = null;
    string foundLogin = null;

    using (DirectoryEntry root = new DirectoryEntry(ldapUrl))
        Using (DirectorySearcher searcher = new DirectorySearcher(root) {
            searcher.SearchScope = SearchScope.Subtree;
            searcher.PropertiesToLoad.Add("sAMAccountName");
            searcher.Filter = string.Format("(&(objectClass=user)(sAMAccountName={0}))", login);

            SearchResult result = null;

            try {
                result = searcher.FindOne();

                if (result == null) 
                    if (string.Equals(login, result.GetDirectoryEntry().Properties("sAMAccountName").Value)) 
                        foundLogin = result.GetDirectoryEntry().Properties("sAMAccountName").Value
            } finally {
                searcher.Dispose();
                root.Dispose();
                if (result != null) result = null;
            }
        }

    if (!string.IsNullOrEmpty(foundLogin)) 
        using (DirectoryEntry root = new DirectoryEntry(ldapUrl.Insert(7, "CN=Partitions,CN=Configuration,DC=").Replace(".", ",DC=")) 
            Using DirectorySearcher searcher = new DirectorySearcher(root)
                searcher.Filter = "nETBIOSName=*";
                searcher.PropertiesToLoad.Add("cn");

                SearchResultCollection results = null;

                try {
                    results = searcher.FindAll();

                    if (results != null && results.Count > 0 && results[0] != null) {
                        ResultPropertyValueCollection values = results[0].Properties("cn");
                        netBiosName = rpvc[0].ToString();
                } finally {
                    searcher.Dispose();
                    root.Dispose();

                    if (results != null) {
                        results.Dispose();
                        results = null;
                    }
                }
            }

    Assert.AreEqual("INTRATESTUSER1", string.Concat(netBiosName, "", foundLogin).ToUpperInvariant())
}

此 SO 問題中提供的其他相關(guān)信息或鏈接.
C# Active Directory:獲取用戶的域名?
如何查找域的 NetBIOS 名稱

Other related information or links available in this SO question.
C# Active Directory: Get domain name of user?
How to find the NetBIOS name of a domain

這篇關(guān)于從 UserPrincipal 對象中獲取 nETBIOSName的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)用)
主站蜘蛛池模板: 亚洲成网| 可以看黄的视频 | 婷婷综合五月天 | 日本韩国欧美在线观看 | 一a级片 | 国产日韩欧美在线 | 久久av一区二区 | 国产我和子的乱视频网站 | 国产重口老太伦 | 麻豆精品国产91久久久久久 | 亚洲一区二区三区四区五区午夜 | 亚洲精品99 | 黄视频欧美 | 成人影 | 免费艹逼视频 | 日韩欧美精品一区 | 中文字幕综合 | 精品亚洲一区二区 | 久久精品99久久 | 久久精品小视频 | 一区二区三区在线观看免费视频 | 亚洲iv一区二区三区 | 欧美激情一区二区三区 | 精品国产aⅴ | 国产免费麻豆视频 | 亚洲成人精品一区 | 日韩国产精品一区二区三区 | 亚洲成人一区 | 欧美 日韩 中文 | 日本一级淫片免费啪啪3 | 亚洲欧洲精品在线 | 一区在线视频 | 中文字幕在线免费观看 | 国产精品久久久久久久久久了 | 亚洲综合区 | 亚洲自拍偷拍欧美 | 国产成人综合网 | av片在线观看 | 成人在线中文字幕 | 久久久久国产精品午夜一区 | 日本不卡视频在线播放 |