C# Web App not working (or is it?)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: C# Web App not working (or is it?)

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    C# Web App not working (or is it?)

    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:
    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>
    &nbsp;&nbsp;
        <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>
    &nbsp;
    </asp:Content>
    PAGE ASPX DESIGNER CODE:
    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;
        }
    }
    CODE BEHIND:
    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)
            {
                
            }
        }
    }
    Web Service Code (*.asmx):
    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();
        }
    }

  2. #2
    Join Date
    Aug 2011
    Posts
    2

    Re: C# Web App not working (or is it?)

    MS Visual Web Developer 2010 Express
    .NET 4.0

    Sorry! ; )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center