Hi everyone!
I have a C# .NET web app where I'm trying to auto-complete a texbox with computer names pulled from Active Directory using AutoCompleteExtender in the Ajax Control Toolkit. The app seems to work fine but is not auto-completing. Can someone review this code and let me know if you see the problem? I don't and there are no errors within VS 2010 either. Ports are open between AD and
I am pasting my code below if you want to try on your own... Help?
HTML:
PAGE ASPX DESIGNER CODE:Code:<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="OpenJob.aspx.cs" Inherits="HostControl.OpenJob" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server"> </ajaxToolkit:ToolkitScriptManager> <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox> <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtUserName" ServiceMethod="findUser" ServicePath="activeDirectorySearch.asmx"> </ajaxToolkit:AutoCompleteExtender> <asp:Button ID="btnGetInfo" runat="server" Text="Get Info" /> <br /> <asp:Label ID="lblEmail" runat="server" Text="Email Address:"></asp:Label> <asp:Label ID="lblEmailResult" runat="server" Text="Label"></asp:Label> <br /> <asp:Label ID="lblPhone" runat="server" Text="Phone Number:"></asp:Label> <asp:Label ID="lblPhoneResult" runat="server"></asp:Label> </asp:Content>
CODE BEHIND:Code:namespace HostControl { public partial class OpenJob { protected global::AjaxControlToolkit.ToolkitScriptManager ScriptManager1; protected global::System.Web.UI.WebControls.TextBox txtUserName; protected global::AjaxControlToolkit.AutoCompleteExtender AutoCompleteExtender1; protected global::System.Web.UI.WebControls.Button btnGetInfo; protected global::System.Web.UI.WebControls.Label lblEmail; protected global::System.Web.UI.WebControls.Label lblEmailResult; protected global::System.Web.UI.WebControls.Label lblPhone; protected global::System.Web.UI.WebControls.Label lblPhoneResult; } }
Web Service Code (*.asmx):Code:using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Services; namespace HostControl { public partial class OpenJob : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } } }
Code:using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.DirectoryServices; [WebService(Namespace = "http://localhost/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService()] public class activeDirectorySearch : System.Web.Services.WebService { [WebMethod()] public string[] findUser(string prefixText) { DirectoryEntry directory = new DirectoryEntry("LDAP://RootDSE"); var defaultNamingContext = directory.Properties["defaultNamingContext"].Value.ToString(); string filter = "(&(cn=*" + prefixText + "*)(!objectClass=user))"; string[] strCats = { "cn" }; List<string> items = new List<string>(); DirectorySearcher dirComp = new DirectorySearcher(directory, filter, strCats, SearchScope.Subtree); SearchResultCollection results = dirComp.FindAll(); //string strOut = null; foreach (SearchResult result in results) { foreach (DictionaryEntry prop in result.Properties) { if (prop.Key.Equals("cn")) { System.Collections.IEnumerable propsEnum = prop.Value as System.Collections.IEnumerable; foreach (object individualValue in propsEnum) { items.Add(individualValue.ToString()); } } } } return items.ToArray(); results.Dispose(); } }


Reply With Quote
Bookmarks