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

推荐订阅源

D
DataBreaches.Net
L
LangChain Blog
博客园_首页
J
Java Code Geeks
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
小众软件
小众软件
WordPress大学
WordPress大学
V
Visual Studio Blog
T
The Blog of Author Tim Ferriss
U
Unit 42
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
C
Check Point Blog
IT之家
IT之家
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
D
Docker
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
I
InfoQ

博客园 - 焰凌

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

    }

}