【发布时间】:2014-11-12 20:23:46
【问题描述】:
我想为我们公司创建一个使用 Active Directory 的目录 Intranet 网站。到目前为止我得到了这个,但是当我在调试模式下运行时,代码会在 searchResultCollection....search.findAll(); 显示中中断:
[DirectoryServicesCOMException (0x80072020):发生操作错误。]
我尝试将 IIS asp.net 模拟更改为启用,但我收到 HTTP 错误 500.24。 我的用户名对 Active Directory 具有读取权限。是否有一些我遗漏的东西,或者有人能指出我正确的方向。我到处找这是我被卡住了。
提前感谢您的帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.DirectoryServices;
using System.Web.Security;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
GetADUsers();
}
public void GetADUsers()
{
DirectoryEntry myLdap = new DirectoryEntry("LDAP://OU=Nix,DC=systems,DC=com");
DirectorySearcher search = new DirectorySearcher(myLdap);
search.CacheResults = true;
search.SearchScope = SearchScope.Subtree;
search.Filter = "(objectlass=person)";
SearchResultCollection allResults = search.FindAll();
foreach (SearchResult sr in allResults)
{
Response.Write(sr.Properties["name"].ToString());
}
}
【问题讨论】:
-
今天重启后我再次测试它运行没有错误。我刚刚添加了 search.propertiestoload("any");并添加了一个网格和绑定数据,效果很好。谢谢标记
标签: c# asp.net iis-7 active-directory ldap