ActiveDirectory からグループ メンバーシップに基づいてユーザーの詳細を取得しようとしています。これはローカルマシンでは機能しますが、サーバーで実行すると機能しません。
私が理解していないのは、グループのメンバーの数を正しく返しますが (特定の方法である必要がありますが、コードのコメントを参照してください)、グループのメンバーの詳細は返さないということです。[DirectoryServicesCOMException (0x80072020): 操作エラーが発生しました。] 何をしても終了します。
//DirectoryEntry DEntry = new DirectoryEntry("LDAP://DOMAIN"); //works only locally
DirectoryEntry DEntry = new DirectoryEntry("LDAP://DOMAIN", "Account", "Password"); //works locally and on the server
DirectorySearcher DSearcher = new DirectorySearcher();
DSearcher.SearchRoot = DEntry;
DSearcher.Filter = "(&(objectClass=group)(cn=GroupName))";
SearchResult SResult = DSearcher.FindOne();
DirectoryEntry DEGroup = new DirectoryEntry(SResult.Path);
System.DirectoryServices.PropertyCollection PCollection = DEGroup.Properties;
//Label1.Text = PCollection["member"].Count.ToString(); //works only locally
Label1.Text = SResult.GetDirectoryEntry().Properties["member"].Count.ToString(); //works locally and on the server
//DirectoryEntry DEUser = new DirectoryEntry("LDAP://DOMAIN/" + PCollection["member"][0].ToString()); //works only locally
DirectoryEntry DEUser = new DirectoryEntry("LDAP://DOMAIN/" + SResult.GetDirectoryEntry().Properties["member"][0].ToString()); //works locally and on the server
//Label2.Text = DEUser.Properties["sAMAccountName"][0].ToString(); //works only locally
DEUser.Close();
DEntry.Close();
DEGroup.Close();
アプリ プール ID は Network Service であり、web.config には次のものが含まれます
<authentication mode="Windows">
<identity impersonate="true" />