.NET 3.5にはありますか?もしそうなら - ADには.NET 3.5の大きな新機能があります - この記事はEthan WilanskiとJoe KaplanのManaging Directory Security Principals in .NET 3.5をチェックしてください。
大きな新機能の1つは、ADのユーザーおよび/またはグループの検索を大幅に簡素化する "PrincipalSearcher"クラスです。
あなたは、.NET 3.5を使用したDirectorySearcherを使用すると、検索条件として、電子メールアドレスを指定して、ユーザ名取得できない場合(1を無数異なるユーザ名があります?!):
DirectoryEntry deRoot = new DirectoryEntry("LDAP://cn=Users,dc=yourdomain,dc=com");
DirectorySearcher deSrch = new DirectorySearcher(deRoot);
deSrch.SearchScope = SearchScope.Subtree;
deSrch.PropertiesToLoad.Add("sn"); // surname = family name
deSrch.PropertiesToLoad.Add("givenName");
deSrch.PropertiesToLoad.Add("samAccountName");
deSrch.Filter = string.Format("(&(objectCategory=person)(mail={0}))", emailAddress);
foreach(SearchResult sr in deSrch.FindAll())
{
// you can access the properties of the search result
if(sr.Properties["sn"] != null)
{
string surname = sr.Properties["sn"][0].ToString();
}
// and so on, for all the other properties, too
}
これが役立つことを願っています!
マーク