.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

วิธีการค้นหาข้อมูลใน LDAP Options · View
blankbrain
Posted: Wednesday, October 15, 2008 2:23:51 PM

Rank: มือสมัครเล่น
Groups: Member

Joined: 9/26/2008
Posts: 27
Location: BKK

ไม่ทราบว่าหากเราต้องการข้อมูลของพนักงานซึ่งเก็บใน active directory LDAP จะเขียนอย่างไรครับ เบื้องต้นผมคอนเน็ตกับ LDAP ได้แล้วครับรีเทิร์นค่า true ออกมาให้ ดังด้านล่างนี้

public bool IsCheckUserExist()
{
 string user="xxx";
 string pass="xxx";
 string domain="LDAP://xxx";  
 DirectoryEntry entry = new DirectoryEntry(domain,user,pass);
 DirectorySearcher direct_search = new DirectorySearcher();
 direct_search.SearchRoot = entry;
 direct_search.Filter = "(&(ObjectClass=user)(SAMAccountName=" + user + "))";
 SearchResultCollection result_col = direct_search.FindAll();
 return result_col.Count > 0;
}

paedotnet
Posted: Friday, October 17, 2008 12:11:51 PM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 354
Location: bkk

แล้วข้อมูลพนักงานอะครับอยู่ในส่วนไหนอะครับเช่น CN,OU,DC ฯ เพราะในการอ้างอิงจะต้องกำหนด กลุ่มให้ถูกเช่น พนักงานอยู่ในกลุ่มของ OU ( Organizegation Unit) เราก็กำหนด path ไป
ที่กลุ่มนี้



[With great power comes great responsibility]
blankbrain
Posted: Friday, October 17, 2008 1:49:19 PM

Rank: มือสมัครเล่น
Groups: Member

Joined: 9/26/2008
Posts: 27
Location: BKK

ด้านล่างนี้คือโค้ดที่ใช้อยู่แต่มันจะต้องระบุพารามิเตอร์ดังเช่น OU=Department ผลลัพธ์จะได้เฉพาะคนที่อยู่ใน OU=Department และหากระบุ DC=xxx ก็จะได้ทุกคนที่อยู่ใน  DC=xxx  ครับ แต่หากผมต้องการได้เฉพาะว่า  DC=xxx มี OU อะไรบ้างทำไงครับ อีกอย่างในแต่ละ CN=user,OU=Department ,DC=xxx นั้นหากผมต้องการหาว่าข้อมูลที่เก็บใน attribute เช่น department , tel,employeeid จะเขียนอย่างไรครับ คุณเป้ ขอบคุณครับ

[WebMethod]
        public ArrayList EnumerateOU(string OuDn)
  {
   ArrayList alObjects = new ArrayList();
   try
   {
    DirectoryEntry directoryObject = new DirectoryEntry("LDAP://" + OuDn,"user","pass");
    foreach (DirectoryEntry child in directoryObject.Children)
    {
     string childPath = child.Path.ToString();
     alObjects.Add(childPath.Remove(0,27));
     //remove the LDAP prefix from the path
     
     child.Close();
     child.Dispose();
    }
    directoryObject.Close();
    directoryObject.Dispose();
   }
   catch (Exception e)
   {
    Console.WriteLine("An Error Occurred: " + e.Message.ToString());
   }
   return alObjects;
  }

Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by