c# - Query Active Directory Status by User's Email -


i facing strange issue. want know whether user's ad account disabled or not providing user's email parameter.

below code working great me set of users in our org. other set of users returning null- though can able verify these set of users in ad manually.

can please me on come issue.

        private string getcurrentdomainpath()         {             directoryentry de =                new directoryentry("ldap://rootdse");              return "ldap://" +                de.properties["defaultnamingcontext"][0].                    tostring();         }          public bool? findaccountstatusbyemail(string email)         {             using (directorysearcher dsearch = new directorysearcher(new directoryentry(getcurrentdomainpath())))             {                 dsearch.searchscope = searchscope.subtree;                 dsearch.filter = "(&(objectcategory=person)(samaccountname=*)(mail=" + email.trim() + "))";                 searchresult sresult = dsearch.findone();                 if (sresult != null)                 {                     directoryentry de = sresult.getdirectoryentry();                     return isactive(de);                 }                 else                 {                     return null;                 }             }         }         private bool isactive(directoryentry de)         {             if (de.nativeguid == null)             {                 return false;             }              int flags = (int)de.properties["useraccountcontrol"].value;              return !convert.toboolean(flags & 0x0002);         } 

update-1: lets have 1 user's email address : abac@mydomain.com when passing email address through code, returning null. when searching in through windows provided tool(find users,contacts , groups) able retrieve user. enter image description here

but noticed in "e-mail :" section user's email different abac@mydomainlbs.com in above picture.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -