c# - Information about the domain could not be retrieved (1355). Not able to read values in LINQ collection -
i trying users name active directory using pricipalcontext. can able results on ienumurable variable principalsearchresult using following code. not able read results under principalsearchresult.
while trying read results principalsearchresult , populate error message principaloperation exception unhandled users code: information domain not retrieved (1355).
i don't know error , unable read values in search result.
here code:
principalcontext oucontext = new principalcontext(contexttype.domain, ad.serverdomain, ad.ldapuser, ad.ldappasswoprd); userprincipalex userpricipalex = new userprincipalex(oucontext); principalsearcher mysearch = new principalsearcher(userpricipalex); mysearch.queryfilter = userpricipalex; ienumerable<userprincipalex> principalsearchresult = mysearch.findall().cast <userprincipalex>(); var s = (from user in oprincipalsearchresult //here getting exception select new user { displayname=user.displayname, emailaddress=user.emailaddress . . . });
how can resolve error , read values in ienumurable collection without exception.
the domain users built-in group have ad users, can query ad users details shown below. here storing details in datatable. can store them list of custom business objects. hope helps!!
string groupname="domain users"; using (groupprincipal objgroupprincipal = getgroupprincipal(fqdn, aousername, aopassword, groupname)) { if (objgroupprincipal != null) using (principalsearchresult<principal> objprincipalsearchresult = objgroupprincipal.getmembers(false)) { objprincipalsearchresult.tolist<principal>().findall(p => p != null).cast<userprincipal>().tolist<userprincipal>() .foreach(delegate(userprincipal objuserprincipal) { datarow druser = dtusers.newrow(); druser["displayname"] = objuserprincipal.displayname; druser["username"] = objuserprincipal.samaccountname; druser["domain"] = fqdn; druser["accountactive"] = objuserprincipal.isaccountlockedout(); druser["firstname"] = ""; druser["initials"] = objuserprincipal.middlename; druser["lastname"] = objuserprincipal.surname; druser["mail"] = objuserprincipal.emailaddress; druser["telephonenumber"] = objuserprincipal.voicetelephonenumber; druser["lastlogon"] = convert.tostring(objuserprincipal.lastlogon); druser["aduserpath"] = convert.tostring(objuserprincipal.distinguishedname); druser["accexpirydate"] = convert.tostring(objuserprincipal.accountexpirationdate); druser["pwdexpirydate"] = ""; dtusers.rows.add(druser); }); } }
and sub methods are
public static groupprincipal getgroupprincipal(string fqdn, string aousername, string aopassword, string groupname) { groupprincipal objgroupprincipal = null; objgroupprincipal = groupprincipal.findbyidentity(getprincipalcontext(fqdn, aousername, aopassword), identitytype.samaccountname, groupname); return objgroupprincipal; } public static principalcontext getprincipalcontext(string fqdn, string aousername, string aopassword) { principalcontext objprincipalcontext = null; objprincipalcontext = new principalcontext(contexttype.domain, fqdn, aousername, aopassword); return objprincipalcontext; }
Comments
Post a Comment