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

如何通過ldap中的域名獲取用戶的用戶名和SID

How to get username and SID for user by a domain name in ldap(如何通過ldap中的域名獲取用戶的用戶名和SID)
本文介紹了如何通過ldap中的域名獲取用戶的用戶名和SID的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試獲取將作為程序輸入的特定域的用戶信息.根據域名,它應該返回用戶名/或用戶的 NT Id 和 SID 的列表.我是 ldap 編程的新手,任何人都可以幫助我獲取此列表.

I am trying to get the user information for a specific domain which will be the input of the program. On the basis of the domain name it should return the list of the users name/ or NT Id and SID of the user. I am new for the ldap programming can any one help me for get this list.

推薦答案

如果您使用 .NET 3.5 及更高版本并談論 Active Directory,那么您應該查看 System.DirectoryServices.AccountManagement (SDS.AM) 命名空間.在此處閱讀所有相關信息:

If you're on .NET 3.5 and up and talking about Active Directory, then you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here:

  • 在 .NET Framework 3.5 中管理目錄安全主體莉>
  • 有關 System.DirectoryServices.AccountManagement 的 MSDN 文檔

基本上,您可以定義域上下文并輕松找到 AD 中的用戶和/或組:

Basically, you can define a domain context and easily find users and/or groups in AD:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // do something here....     
   var usersSid = user.Sid;

   // not sure what you mean by "username" - the "DisplayName" ? The "SAMAccountName"??
   var username = user.DisplayName;
   var userSamAccountName = user.SamAccountName;
}

新的 S.DS.AM 使在 AD 中與用戶和組一起玩變得非常容易!

The new S.DS.AM makes it really easy to play around with users and groups in AD!

更新:如果您需要遍歷域的所有用戶 - 試試這個:

Update: if you need to loop through all the users of a domain - try this:

您可以使用 PrincipalSearcher 和query-by-example"主體來進行搜索:

You can use a PrincipalSearcher and a "query-by-example" principal to do your searching:

// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// define a "query-by-example" principal - here, we search for a UserPrincipal 
UserPrincipal qbeUser = new UserPrincipal(ctx);

// create your principal searcher passing in the QBE principal    
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

// find all matches
foreach(var found in srch.FindAll())
{
    UserPrincipal user = found as UserPrincipal;

    if(user != null)
    {
       // do whatever here 
       var usersSid = user.Sid;

       // not sure what you mean by "username" - the "DisplayName" ? 
       var username = user.DisplayName;
       var userSamAccountName = user.SamAccountName;
    }
}

更新 #2:如果您不能(或不想)使用 S.DS.AM 方法 - 這是最簡單的方法,對于 Active目錄,到目前為止 - 那么你需要回退到 System.DirectoryServices 類和方法:

Update #2: if you can't (or don't want to) use the S.DS.AM approach - which is the easiest, for Active Directory, by far - then you need to fall back to the System.DirectoryServices classes and methods:

// define the root of your search
DirectoryEntry root = new DirectoryEntry("LDAP://dc=YourCompany,dc=com");

// set up DirectorySearcher  
DirectorySearcher srch = new DirectorySearcher(root);
srch.Filter = "(objectCategory=Person)";
srch.SearchScope = SearchScope.Subtree;

// define properties to load
srch.PropertiesToLoad.Add("objectSid");
srch.PropertiesToLoad.Add("displayName");

// search the directory
foreach(SearchResult result in srch.FindAll())
{
   // grab the data - if present
   if(result.Properties["objectSid"] != null && result.Properties["objectSid"].Count > 1)
   {
       var sid = result.Properties["objectSid"][0];
   }

   if(result.Properties["displayName"] != null && result.Properties["displayName"].Count > 0)
   {
       var userName = result.Properties["displayName"][0].ToString();
   }
}

這篇關于如何通過ldap中的域名獲取用戶的用戶名和SID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應該總是在 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#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調用)
主站蜘蛛池模板: 四虎在线观看 | 黄色在线免费网站 | 亚洲国产精品suv | 欧美日韩黄 | 成人免费淫片aa视频免费 | av国产精品毛片一区二区小说 | 美女在线视频一区二区三区 | 福利视频二区 | 羞羞的视频在线 | 国产一区二区三区久久久久久久久 | 黄色在线| 国产欧美日韩视频 | 日韩中文视频 | 亚洲欧美日本在线 | 国产精品视频 | 欧美精选一区二区 | 91精品免费视频 | 亚洲第一天堂无码专区 | 国产精品一区二区免费 | 99精品久久 | 97精品国产97久久久久久免费 | 天堂久| 九九久久久久久 | 欧美精品在线一区 | 国户精品久久久久久久久久久不卡 | 日本不卡一区二区三区在线观看 | 在线成人免费视频 | 精品欧美一区二区三区 | 日韩三级在线 | 男人电影天堂 | 国产精品久久久久久久免费观看 | 亚洲大片 | 日韩久久精品 | 国产a一区二区 | 午夜精品一区二区三区在线播放 | 久久久久久国产精品三区 | 午夜国产一级片 | 久久精品欧美电影 | 亚洲欧美在线一区 | 亚洲精品乱码久久久久久按摩观 | 国产精品一区二区在线 |