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

在 Active Directory 中使用登錄名查找用戶

Finding a User in Active Directory with the Login Name(在 Active Directory 中使用登錄名查找用戶)
本文介紹了在 Active Directory 中使用登錄名查找用戶的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我可能只是愚蠢,但我正在嘗試使用登錄名(域用戶")從 C# 中查找 Active Directory 中的用戶.

I'm possibly just stupid, but I'm trying to find a user in Active Directory from C#, using the Login name ("domainuser").

我的骨架"廣告搜索功能通常如下所示:

My "Skeleton" AD Search Functionality looks like this usually:

de = new DirectoryEntry(string.Format("LDAP://{0}", ADSearchBase), null, null, AuthenticationTypes.Secure);
ds = new DirectorySearcher(de);
ds.SearchScope = SearchScope.Subtree;
ds.PropertiesToLoad.Add("directReports");
ds.PageSize = 10;
ds.ServerPageTimeLimit = TimeSpan.FromSeconds(2);
SearchResult sr = ds.FindOne();

現在,如果我擁有用戶的完整 DN(ADSearchBase 通常指向 Active Directory 中的我們的用戶"OU),這將起作用,但我根本不知道如何根據域用戶"語法.

Now, that works if I have the full DN of the user (ADSearchBase usually points to the "Our Users" OU in Active Directory), but I simply have no idea how to look for a user based on the "domainuser" syntax.

任何指針?

推薦答案

你需要設置一個過濾器 (DirectorySearcher.Filter) 類似于:

You need to set a filter (DirectorySearcher.Filter) something like:

"(&(objectCategory=person)(objectClass=user)(sAMAccountName={0}))"

"(&(objectCategory=person)(objectClass=user)(sAMAccountName={0}))"

請注意,您只為屬性 sAMAccountName 指定用戶名(不帶域).要搜索域用戶,首先找到所需域的命名上下文,然后在那里搜索 sAMAccountName.

Note that you only specify the username (without the domain) for the property sAMAccountName. To search for domainuser, first locate the naming context for the required domain, then search there for sAMAccountName.

順便說一下,在使用 String.Format 構建 LDAP 查詢字符串時,您通常應該小心轉義任何特殊字符.帳戶名稱可能不是必需的,但如果您按其他屬性進行搜索,例如用戶的名字(givenName 屬性)或姓氏(sn 屬性)名稱,則可能是必需的.我有一個實用方法 EscapeFilterLiteral 來執行此操作:您可以像這樣構建字符串:

By the way, when building LDAP query strings using String.Format, you should generally be careful to escape any special characters. It probably isn't necessary for an account name, but could be if you're searching by other properties such as the user's first (givenName property) or last (sn property) name. I have a utility method EscapeFilterLiteral to do this: you build your string like this:

String.Format("(&(objectCategory=person)(objectClass=user)(sn={0}))", 
              EscapeFilterLiteral(lastName, false)); 

其中 EscapeFilterLiteral 實現如下:

where EscapeFilterLiteral is implemented as follows:

public static string EscapeFilterLiteral(string literal, bool escapeWildcards)
{
    if (literal == null) throw new ArgumentNullException("literal");

    literal = literal.Replace("\", "\5c");
    literal = literal.Replace("(", "\28");
    literal = literal.Replace(")", "\29");
    literal = literal.Replace("

主站蜘蛛池模板:
欧美一区二区三区在线观看视频
|
免费观看a级毛片在线播放
黄网站免费入口
|
a级片在线观看
|
日韩欧美二区
|
热99精品视频
|
国内自拍视频在线观看
|
日日夜夜视频
|
亚洲一区在线播放
|
av国产精品毛片一区二区小说
|
欧美手机在线
|
久久高潮|
欧美一区在线视频
|
中文字幕视频一区
|
成年人精品视频在线观看
|
中文字幕观看
|
国产精品久久久久久久粉嫩
|
免费黄视频网站
|
男女午夜激情视频
|
www.99re
|
亚洲性人人天天夜夜摸
|
国产精品欧美精品日韩精品
|
国产精品99久久久久久久vr
|
99久久精品免费视频
|
国产 欧美 日韩 一区
|
日韩欧美国产成人一区二区
|
久久久久无码国产精品一区
|
天堂视频一区
|
美国av毛片
|
视频一区二区在线
|
毛片a级毛片免费播放100
|
中文字幕视频在线观看
|
人人鲁人人莫人人爱精品
|
伊人狠狠操
|
成人免费精品视频
|
亚洲精品国产区
|
黄色精品|
国产成人免费
|
亚洲国产日本
|
中文成人无字幕乱码精品
|
亚洲一区二区日韩
|
天堂一区二区三区
|