久久久久久久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("

主站蜘蛛池模板:
av国产精品|
精品久久久久久久人人人人传媒
|
久久久久久亚洲精品
|
www.国产日本|
国产欧美久久一区二区三区
|
精品久久久久久18免费网站
|
免费视频一区
|
日日摸夜夜添夜夜添精品视频
|
久久99精品视频
|
久久久精品一区二区三区
|
91久久综合|
在线视频91
|
欧美成人精品一区二区男人看
|
日本黄色不卡视频
|
97caoporn国产免费人人
|
久久久久久国产精品
|
午夜视频在线视频
|
国产精品久久久久久久模特
|
亚洲视频免费在线观看
|
狠狠狠色丁香婷婷综合久久五月
|
99精品观看|
欧美在线网站
|
99国产精品久久久久老师
|
夜夜骑天天干
|
一级毛片视频在线观看
|
午夜精品一区二区三区在线视频
|
免费在线看黄
|
婷婷久久综合
|
久久精品一区二区三区四区
|
免费一区在线
|
欧美精品v
|
亚洲综合婷婷
|
国产精品久久久久久久久久久久午夜片
|
欧美在线a
|
免费黄网站在线观看
|
中文字幕在线第一页
|
亚洲欧美第一视频
|
国产精品久久久99
|
99热都是精品
|
99久久国产综合精品麻豆
|
成人国产精品久久久
|