Active Directory and asp .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iscuf
    New Member
    • Mar 2008
    • 1

    Active Directory and asp .net

    Hello,

    I'm building a web app where I like to query my users from active directory.
    The code I'm working on it works fine for a user where all the properties that I'm query are filled in.

    I'm trying already for a week to check if a property is empty but I'm stuck.

    I need a method how I can check if a property is empty so I can use a string like "property empty". after testing I bring the AD up-to-date.

    I hope there are some specialist over here so I can find a solution for my problem.

    Many thanks in advance.

    Wim (starter)

    Here under my code

    using System;
    using System.Data;
    using System.Configur ation;
    using System.Linq;
    using System.Web;
    using System.Web.Secu rity;
    using System.Web.UI;
    using System.Web.UI.H tmlControls;
    using System.Web.UI.W ebControls;
    using System.Web.UI.W ebControls.WebP arts;
    using System.Xml.Linq ;
    using System.Director yServices;
    using System.Director yServices.Activ eDirectory;
    using System.Collecti ons.Generic;


    using System.Componen tModel;

    /// <summary>
    /// Summary description for AdSearch
    /// </summary>
    namespace HelpdeskApplica tion
    {
    public class AdSearch
    {
    public AdSearch()
    {
    //
    // TODO: Add constructor logic here
    //
    }
    public static DirectoryEntry GetDirectoryEnt ry()
    {
    DirectoryEntry dirent = new DirectoryEntry( );
    dirent.Path = "LDAP://domain.local";

    dirent.Authenti cationType = AuthenticationT ypes.Secure;

    return dirent;
    }


    public static List<adGetSet> GetAllADUsers()
    {
    DirectoryEntry adFolderObject = GetDirectoryEnt ry();
    DirectorySearch er adSearcherObjec t = new DirectorySearch er(adFolderObje ct);
    adSearcherObjec t.SearchScope = SearchScope.Sub tree;
    adSearcherObjec t.Filter = "(&(objectCateg ory=person)(obj ectClass=user)( !description=bu ilt-in*))";
    adSearcherObjec t.PropertiesToL oad.Add("displa yName");
    adSearcherObjec t.PropertiesToL oad.Add("SAMAcc ountName");
    adSearcherObjec t.PropertiesToL oad.Add("title" );
    adSearcherObjec t.PropertiesToL oad.Add("mail") ;
    adSearcherObjec t.PropertiesToL oad.Add("depart ment");
    adSearcherObjec t.PropertiesToL oad.Add("manage r");
    adSearcherObjec t.PropertiesToL oad.Add("physic alDeliveryOffic eName");
    adSearcherObjec t.PropertiesToL oad.Add("pager" );
    adSearcherObjec t.PropertiesToL oad.Add("homeph one");
    adSearcherObjec t.PropertiesToL oad.Add("facsim ileTelephoneNum ber");
    adSearcherObjec t.PropertiesToL oad.Add("mobile ");


    List<adGetSet> adAllUsers = new List<adGetSet>( );
    adGetSet adUsers = new adGetSet();

    foreach (SearchResult adObject in adSearcherObjec t.FindAll())
    {

    if (adObject.Prope rties["SAMAccountName "][0].ToString().Len gth == 5)
    {
    adUsers.ADUsern ame = adObject.Proper ties["displayNam e"][0].ToString();
    adUsers.ADSAMAc countName = adObject.Proper ties["SAMAccountName "][0].ToString();

    /// AD Title of user
    /// check if the propertie is empty
    if (string.IsNullO rEmpty(adObject .Properties["title"][0].ToString()))
    {
    adUsers.ADTitle = "noTitle";
    }
    else
    {
    adUsers.ADTitle = adObject.Proper ties["title"][0].ToString();
    }
    ///End check AD Title of user

    adUsers.ADMail = adObject.Proper ties["mail"][0].ToString();
    adUsers.ADDepar tment = adObject.Proper ties["department "][0].ToString();
    adUsers.ADManag er = adObject.Proper ties["manager"][0].ToString();
    adUsers.ADDock = adObject.Proper ties["physicalDelive ryOfficeName"][0].ToString();
    adUsers.ADPc = adObject.Proper ties["pager"][0].ToString();
    adUsers.ADPhone = adObject.Proper ties["homephone"][0].ToString();
    adUsers.ADFax = adObject.Proper ties["facsimileTelep honeNumber"][0].ToString();
    adUsers.ADGsm = adObject.Proper ties["mobile"][0].ToString();
    adAllUsers.Add( adUsers);
    }
    }
    return adAllUsers;
    }

    }
    }
  • shinevpaul
    New Member
    • Mar 2008
    • 7

    #2
    Check the proprty is empty or not using Properties.Cont ains("property" )

    eg: if(adObject .Properties.Con tains("title"))

    IsNullOrEmpty() function will not check the property is null

    Comment

    Working...