【问题标题】:ActiveDirectory query doesn’t work from serverActive Directory 查询在服务器上不起作用
【发布时间】:2012-08-14 12:17:08
【问题描述】:

我正在尝试根据 ActiveDirectory 的组成员身份获取用户详细信息。这在我的本地计算机上有效,但在我在服务器上运行时无效。

我不明白的是它会正确返回组成员的数量(虽然它必须以特定的方式,参见代码中的 cmets),而不是组成员的任何详细信息。我最终得到一个 [DirectoryServicesCOMException (0x80072020): An operation error occurred.] 不管我做什么。

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

【问题讨论】:

    标签: c# active-directory


    【解决方案1】:

    我怀疑它在您的机器上工作,因为您自己在调试器中运行。根据您的 ActiveDirectory 设置,您不能以匿名用户的身份查询目录(网络服务本身就是这样)。

    最简单的测试是对您域中的用户的应用程序池标识(您的作为测试),如果它有效,您将确认根本原因。

    【讨论】:

    • 正确,我自己跑。我尝试将 App Pool Identity 设置为域用户帐户,但我用来显示结果的网页只返回“服务不可用”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多