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

如何確定帳戶的類型(AD 用戶與 AD 組)?

How to determine the type (AD User vs. AD Group) of an account?(如何確定帳戶的類型(AD 用戶與 AD 組)?)
本文介紹了如何確定帳戶的類型(AD 用戶與 AD 組)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個(gè)關(guān)于確定帳戶名稱類型(用戶或組)的問題.
例如,我有兩個(gè)字符串,比如Adventure-worksdavid"和Adventure-worksadmins",第一個(gè)代表名為 david 的用戶,第二個(gè)代表一個(gè) AD 組.

I have a question about determining the type (User or Group) of a account name.
For example, I have two strings, say "Adventure-worksdavid" and "Adventure-worksadmins", the first represents a user named david, and the second represents an AD group.

我的問題是如何確定這些帳戶的類型(用戶或 AD 組)?有什么方便的方法可以用嗎?

My question is how can I determin the type(User or AD group) of these account? Are there convenient method I can use?

感謝任何評(píng)論.謝謝.

推薦答案

您使用的是哪個(gè)版本的 .NET?

What version of .NET are you on??

如果您使用 .NET 3.5,請(qǐng)參閱這篇優(yōu)秀的MSDN 文章,了解如何Active Directory 界面發(fā)生了很大變化.

If you're on .NET 3.5, see this excellent MSDN article on how the Active Directory interface has changed quite a bit.

如果你使用 .NET 3.5,你可以寫:

If you're on .NET 3.5, you could write:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN");
Principal myObject = Principal.FindByIdentity(ctx, "your name value");

通常,您必須只傳入用戶名 - 反斜杠后的部分 - 而不是整個(gè) DOMAINUSERNAME 字符串.

Typically, you'd have to pass in just the user name - the part after the backslash - not the whole DOMAINUSERNAME string.

這個(gè)主體"現(xiàn)在要么是 UserPrincipal 要么是 GroupPrincipal(或者它可以是其他類型的主體,例如 ComputerPrincipal):

This "Principal" now either is a UserPrincipal or a GroupPrincipal (or it could some other type of principal, e.g. ComputerPrincipal):

if(myObject is UserPrincipal)
{
    // you have a user
}
else if(myObject is GroupPrincipal)
{
    // you have a group
}

你可以從那里繼續(xù).

如果您使用的是 .NET 1.x/2.0/3.0,則必須使用稍微復(fù)雜一點(diǎn)的過程來創(chuàng)建 DirectorySearcher 并搜索您的對(duì)象:

If you're on .NET 1.x/2.0/3.0, you'd have to use the slightly more involved procedure of creating a DirectorySearcher and searching for your object:

// create root DirectoryEntry for your search
DirectoryEntry deRoot = new DirectoryEntry("LDAP://dc=YourCompany,dc=com");

// create searcher            
DirectorySearcher ds = new DirectorySearcher(deRoot);

ds.SearchScope = SearchScope.Subtree;

// define LDAP filter - all you can specify is the "anr" (ambiguous name
// resolution) attribute of the object you're looking for
ds.Filter = string.Format("(anr={0})", "YourNameValue");

// define properties you want in search result(s)
ds.PropertiesToLoad.Add("objectCategory");
ds.PropertiesToLoad.Add("displayName");

// search
SearchResult sr = ds.FindOne();

// check if we get anything back, and if we can check the "objectCategory" 
// property in the search result
if (sr != null)
{
    if(sr.Properties["objectCategory"] != null)
    {
       // objectType will be "Person" or "Group" (or something else entirely)
       string objectType = sr.Properties["objectCategory"][0].ToString();
    }
}

馬克

這篇關(guān)于如何確定帳戶的類型(AD 用戶與 AD 組)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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 時(shí)如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調(diào)用)
主站蜘蛛池模板: 精品国产免费一区二区三区演员表 | 亚洲国产成人精品久久 | 懂色中文一区二区在线播放 | 女同久久另类99精品国产 | 久久久久久久久久久高潮一区二区 | 日本在线中文 | 91精品中文字幕一区二区三区 | 国内精品久久久久久 | 我要看免费一级毛片 | 中文字幕在线观看 | 午夜免费网站 | www.99精品 | 免费激情网站 | 日韩亚洲欧美一区 | 成人深夜福利网站 | 国产欧美一区二区三区免费 | 91精品国产综合久久婷婷香蕉 | 日本不卡免费新一二三区 | 日本中文字幕在线视频 | 欧洲成人 | 日韩欧美一区二区三区免费观看 | caoporn视频在线 | 99福利| 激情一区二区三区 | 午夜精品一区二区三区在线 | 精品国产乱码久久久久久88av | 久久99深爱久久99精品 | 三级视频在线观看电影 | 免费观看一级特黄欧美大片 | 免费一区二区三区 | 亚洲va欧美va天堂v国产综合 | 欧美一区二区免费 | 在线91 | 欧美一级黄 | 在线播放国产一区二区三区 | 中文字幕动漫成人 | 在线中文字幕视频 | 国产高清在线精品一区二区三区 | 国产一区影院 | 中文字幕日韩在线观看 | 天天干视频 |