0

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" />
4

1 に答える 1

1

あなたは自分自身のようにデバッガーで実行しているので、あなたのマシンで動作していると思われます。ActiveDirectory の設定によっては、ディレクトリを匿名ユーザーとしてクエリすることはできません (これは、Network Service 自体が示すものです)。

最も簡単なテストは、ドメイン内のユーザー (テストとしてのユーザー) に対するアプリケーション プール ID に対するものであり、それが機能するかどうかの根本原因を確認します。

于 2012-08-14T12:37:36.423 に答える