ユーザー名とドメインに基づいてユーザーのフルネームを取得する関数があります。この関数は、偽装されたユーザーのASP.NETスレッドで実行されます。 リモートADブランチでDirectory searcherを使用すると、プロパティの代わりにSID番号が取得されていると考えられます(別のボックスで確認できません)。Active Directory検索で遅延バインディングを克服する方法
public string GetUserFullName(string userName, string domainName)
{
DirectoryEntry rootEntry = new DirectoryEntry("GC://dc=company,dc=net");
string filter = string.Format("(&(objectCategory=person)(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(userPrincipalName={0}@{1}.company.net))", userName, domainName);
DirectorySearcher searcher = new DirectorySearcher(rootEntry, filter, new string[] { "displayName" });
rootEntry.AuthenticationType = AuthenticationTypes.Secure;
searcher.PageSize = 1000;
searcher.ServerTimeLimit = new TimeSpan(0, 10, 0);
searcher.ReferralChasing = ReferralChasingOption.All;
searcher.Asynchronous = false;
SearchResult result = searcher.FindOne();
if (result != null)
{
return (string) result.Properties["displayName"][0];
}
else
{
throw new Exception("Active Directory could not resolve your user name");
}
}
It's NET 2.0です。これを指摘してくれてありがとう! エイドリアン –