下面是我的代码。我想检索网格中名字或姓氏相同的所有用户。但是这里我在网格中对名称本身进行了排序。
我让用户选择输入用户名。一旦他输入名称,我应该能够在 Active Directory 中搜索并返回以用户输入的文本开头的所有用户。
我应该能够显示所有可能性,例如,如果用户输入,adam
我应该让他选择是否要查看adam josef
等adam john
任何建议都会有所帮助。
这是代码
DirectoryEntry de = new DirectoryEntry("ADConnection");
DirectorySearcher deSearch = new DirectorySearcher(de);
//set the search filter
deSearch.SearchRoot = de;
String UserName = txt_To.Text;
deSearch.Filter = "(&(objectCategory=user)(GivenName=*" + UserName + "*))";
string[] arrPropertiesToLoad = { "sn" };
deSearch.PropertiesToLoad.AddRange(arrPropertiesToLoad);
SearchResultCollection sResultColl = deSearch.FindAll();//Getting undefined error
Gridview1.DataSource = sResultColl ;
Gridview1.DataBind();
这是堆栈跟踪
[COMException (0x80004005): Unspecified error]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +439513
System.DirectoryServices.DirectoryEntry.Bind() +36
System.DirectoryServices.DirectoryEntry.get_AdsObject() +31
System.DirectoryServices.DirectorySearcher。 FindAll(Boolean findMoreThanOne) +78
System.DirectoryServices.DirectorySearcher.FindAll() +9
Certificate.WebForm4.btngo0_Click(Object sender, EventArgs e) 在 C:\Users\273714\documents\visual studio 2010\Projects\Certificate\Certificate\ WebForm4.aspx.cs:202
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
+118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page .RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) +5563