活动目录Web服务和AutoCompleteExtender [英] Active Directory Web Service and AutoCompleteExtender

查看:199
本文介绍了活动目录Web服务和AutoCompleteExtender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次与Active Directory,以及Ajax控件工具包玩。我正在试图做的是当用户开始在文本框中输入自己的名字,它会试图在AD中列出来自动完成他们的名字。每一个例子,我可以找到关于使用AutoCompleteExtender,它指的是在ServicePath一个ASMX文件。

This is my first time playing with Active Directory, as well as the Ajax Control Toolkit. What I'm trying to do is when a user starts to type their name in a textbox, it will attempt to auto-complete their name as listed in AD. Every example I can find on using the AutoCompleteExtender, it's referring to an ASMX file in the ServicePath.

我已经设法弄清楚如何增加我们的广告网络服务作为服务引用到我的项目。 任何人都可以提供我如何能得到AutoCompleteExtender承认并与我的广告服务引用起到任何指导或例子?它甚至有可能?

I've managed to figure out how to add our AD web service as a service reference to my project. Can anyone provide any guidance or examples on how I can get AutoCompleteExtender to recognize and play with my AD service reference? Is it even possible?

感谢您的任何援助。

推荐答案

经过反复研究,并从我们的系统管理员帮助,以获得正确的LDAP路径,我终于得到了这个工作。我张贴了code,以便其他的可以从中受益。 (请注意,我第一次安装AJAX控件工具包的.NET 4.0。)

After much research and help from our system admins to get the correct LDAP path, I've finally got this working. I'm posting the code so other's can benefit from it. (Note that I first installed AJAX Control Toolkit for .NET 4.0.)

Default.aspx的:

<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True"></ajaxToolkit:ToolkitScriptManager>
<asp:TextBox ID="txtSearchAD" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ServiceMethod="findEmp"
MinimumPrefixLength="3"
CompletionInterval="100"
EnableCaching="true"
CompletionSetCount="10"
TargetControlID="txtSearchAD"
ID="ace1"
runat="server"
FirstRowSelected="false" ServicePath="ADS.asmx">
</ajaxToolkit:AutoCompleteExtender>

ADS.asmx.cs:

namespace EventTracking
{
    /// <summary>
    /// Summary description for ADS
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]

    public class ADS : System.Web.Services.WebService
    {

        [WebMethod]
        public string[] findEmp(string prefixText, int count)
        {            
            DirectoryEntry directory = new DirectoryEntry();
            directory.Path = "LDAP://DC=yourdomain,DC=com";  //CHANGE to your LDAP path
            string filter = "(&(cn=" + prefixText + "*))";
            string[] strCats = { "cn" };
            List<string> items = new List<string>();
            DirectorySearcher dirComp = new DirectorySearcher(directory, filter, strCats, SearchScope.Subtree);
            SearchResultCollection results = dirComp.FindAll();
            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)
                        {
                            if (individualValue.ToString().IndexOf(prefixText) != 0)
                            {
                                items.Add(individualValue.ToString());
                            }
                        }
                    }
                }
            }
            return items.ToArray();
        }
    }
}

享受!

这篇关于活动目录Web服务和AutoCompleteExtender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆