我正在尝试根据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();
App Pool Identity是网络服务,web.config包含
<authentication mode="Windows">
<identity impersonate="true" />
答案 0 :(得分:1)
我怀疑它在你的机器上工作,因为你在自己的调试器中运行。根据您的ActiveDirectory设置,您无法以匿名用户身份查询目录(这是网络服务自身的用途)。
最简单的测试是针对您域中用户的应用程序池标识(您作为测试),如果有效,您将确认根本原因。