0

Ajaxを使用したオートコンプリートを使用してASP.NETアプリケーションを構築したいと思います。ActiveDirectoryを使用してDatahowDisplaynameを取得したいと思います。

ここに私のコード:

ASPX:

    <tr>
            <td><asp:Label ID="lblVertreter" runat="server" /></td>
            <td>
            <asp:TextBox ID="txtVertreter" runat="server"></asp:TextBox>
            <asp:AutoCompleteExtender ID="AutoComlete" runat="server" TargetControlID="txtVertreter" ServiceMethod="MitarbeiterErmitelln" ServicePath="Service1.asmx"></asp:AutoCompleteExtender>
            AutoCompleteExtender
            </td>
</tr>

asmxコード:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.DirectoryServices;

namespace ADWebService
{

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class Service1 : System.Web.Services.WebService
    {
        public static string GetLdapProperty(SearchResult searchResult, string PropertyName)
        {

            if (searchResult.Properties.Contains(PropertyName))
            {
                return searchResult.Properties[PropertyName][0].ToString();
            }
            else
            {
                return string.Empty;
            }

        }

        [WebMethod]
        public string[] MitarbeiterErmitelln(string prefix)
        {
            string filterung = "((&(objectClass=user)(objectCategory=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(sn=*)(|(telephoneNumber=*)(mail=*))(displayName=*" + prefix + "*)))";

            string ADPfad = "Domain";

            int Counter = 0;

            List<Benutzer> result = new List<Benutzer>();

            DirectoryEntry Entry = new DirectoryEntry(ADPfad);

            DirectorySearcher Searcher = new DirectorySearcher(Entry, filterung);

            foreach (SearchResult usr in Searcher.FindAll())
            {
                result.Add(new Benutzer()
                {
                    DisplayName = GetLdapProperty(usr, "displayName"),

                });
                Counter++;
            }

            return result.ToArray(); 
        }

    }
}

//The Class Benutzer is my Model Class

なにが問題ですか。Active Directoryを直接使用したい!

4

0 に答える 0