【发布时间】:2023-06-04 07:22:01
【问题描述】:
我正在尝试在 Windows Server 2008 R2(安装了 IIS7)上运行的 ASP.Net (4.0) 应用程序中查询 AD。 (作为 2.0 应用程序运行时也会失败)
这对我来说并不新鲜,因为我以前做过很多次。我编写了一个小的 ASP.Net 程序,它在我自己的机器上运行良好(带有 IIS6 的 Windows XP),但在 2008 机器上运行时失败。
(结果是您在文本框中看到用户所属的组列表)
(on button_click)
var userName = txtUserName.Text;
if (userName.Trim().Length == 0)
{
txtResults.Text = "-- MISSING USER NAME --";
return;
}
var entry = new DirectoryEntry("LDAP://blah.blah/DC=blah,DC=blah",
"cn=acct, dc=blah, dc=blah",
"pass");
var search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + userName + ")";
search.PropertiesToLoad.Add("memberOf");
var groupsList = new StringBuilder();
var result = search.FindOne();
if (result != null)
{
int groupCount = result.Properties["memberOf"].Count;
for (int counter = 0; counter < groupCount; counter++)
{
groupsList.Append((string)result.Properties["memberOf"][counter]);
groupsList.Append("\r\n");
}
}
txtResults.Text = groupsList.ToString();
当我运行此代码时,我在 search.FindOne() 上收到以下错误:
System.DirectoryServices.DirectoryServicesCOMException (0x8007203B): A local error has occurred.
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindOne()
at WebApplication1._Default.btnSearch_Click(Object sender, EventArgs e)
我们已经对此进行了大量研究,并调整了我们能想到的每一个 IIS7 设置,但到目前为止还没有。有什么线索吗?
【问题讨论】:
标签: c# asp.net windows windows-server-2008 directoryservices