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

推荐订阅源

博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
The Cloudflare Blog
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
F
Fortinet All Blogs
J
Java Code Geeks
人人都是产品经理
人人都是产品经理
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
爱范儿
爱范儿
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
小众软件
小众软件
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
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

    }

}