惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
博客园 - 【当耐特】
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
MyScale Blog
MyScale Blog
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
I
InfoQ
B
Blog RSS Feed
腾讯CDC
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
雷峰网
雷峰网
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
DataBreaches.Net
The Cloudflare Blog
V
V2EX
S
SegmentFault 最新的问题

博客园 - 焰凌

Poor code: Dynamic changing of table schema When we need to inherit from WSS WebPart class? The issue of upload big file on SharePoint with IIS7 Why no effects when change the "Site Master Page Settings" from "Site Actions - Site Settings - Look and Feel - Master Page"? 怎样在MOSS2007和WSS3.0中修改服务帐户和密码 HttpApplication机制 "NOT IN", "JOIN...IS NULL", "NOT EXISTS" 之间的效率对比 为SharePoint新项目做准备 MOSS 2007 SSP (1) How to create and delete a SharePoint site by web application Received DGT's document 水晶报表PUSH模式多个表数据的显示 上海电信之具有地域歧视的霸王条款 来上海一年多了,第一次感冒! differentia of [string str=null;] and [string str="";] 搬家了,没宽带了 工作以后 找不到状态了! 页面缓存的困扰
Search user of specific domain name
焰凌 · 2007-09-07 · via 博客园 - 焰凌
 

Usually, we use a LDAP search filter to find a user. The filter like "(SAMAccountName=user alias)".

But there is a special situation is: The domain what the LDAP path assign has several sub-domains, and there are several users of these sub-domains have same alias.

E.g.
The LDAP path is "
GC://DC=root, DC=com".
There are two sub-domains of root domain:
GC://DC=sub1, DC=root, DC=com
GC://DC=sub2, DC=root, DC=com

There are two users are:
sub1\username
sub2\username

We cannot write a filter like "(!(DomainName=domain name)(SAMAccountName=user alias))". If we use the filter "(SAMAccountName=user alias)" to search from "GC://DC=root, DC=com", we will get two results.

Which is our real target?

So, we must identify the distinguishedName of the user with regular expression "DC *=[^,]+" to get the use's domain name.

SearchResultCollection results = mySearcher.FindAll();

// check domain name

foreach (SearchResult result in results)

{

    string dn = result.Properties["distinguishedName"][0].ToString();

    Match m = Regex.Match(dn, "DC *=[^,]+");

    string mValue = Regex.Replace(m.Value, @"[\s]", "", RegexOptions.IgnoreCase);

    if (string.Compare(mValue, "dc=" + userDomain, true) == 0)

    {

        // The target is found

    }

}