c# - Cannot get LDAP connection working - always "Unknown error" -
i'm researching need build active directory search tool used in c# asp.net web app.
i know little ad (and don't particularly want know more necessary) i've asked our tech ops set dummy instance on server. they've done giving domain dummy.local
i need work out ldap connection string. here i'm stuck. i'm using user account member of domain admins. after loads of hunting round web i've tried sorts of things work out various components of ldap connection string. example, if run following in cmd.exe domain admin user on server...
dsquery user -samid "username" | dsget user -memberof -expand
...this gives me following information:
"cn=domain admins,cn=users,dc=dummy,dc=local" "cn=remote desktop users,cn=builtin,dc=dummy,dc=local" "cn=users,cn=builtin,dc=dummy,dc=local" "cn=administrators,cn=builtin,dc=dummy,dc=local" "cn=domain users,cn=users,dc=dummy,dc=local" "cn=denied rodc password replication group,cn=users,dc=dummy,dc=local"
i've run following in c# console app...
using (var context = new principalcontext(contexttype.domain)) using (var comp = computerprincipal.findbyidentity(context, environment.machinename)) { console.writeline(string.join(",", comp.distinguishedname.split(',').skipwhile(s => !s.startswith("ou=")).toarray())); }
...and gives me following:
ou=domain controllers,dc=dummy,dc=local
i thought therefore had properties needed build ldap connection string. ended this:
ldap://comsecwebdev.dummy.local/ou=domain controllers,/cn=domain admins,/cn=users,/dc=dummy,/dc=local
i've tried using connection string, username , password of domain admin know correct, try gives me same error:
system.runtime.interopservices.comexception (0x80005000): unknown error (0x80005000) @ system.directoryservices.directoryentry.bind(boolean throwiffail) @ system.directoryservices.directoryentry.bind() @ system.directoryservices.directoryentry.get_adsobject() @ system.directoryservices.directorysearcher.findall(boolean findmorethanone) @ system.directoryservices.directorysearcher.findone()
since error gives me no detail have no idea i'm doing wrong. i'm sure i'm not getting connection string right, i've no idea how work out correct string.
for completeness, here console code i'm testing with:
static void main(string[] args) { var connstring = configurationsettings.appsettings["lc"]; var username = configurationsettings.appsettings["lu"]; var password = configurationsettings.appsettings["lpw"]; using (directoryentry de = new directoryentry(connstring, username, password)) { directorysearcher search = new directorysearcher(de); search.pagesize = 1001;// pull more 100 records. directorysearcher directorysearcher = new directorysearcher(de); directorysearcher.filter = string.format("(&(objectclass=user)(objectcategory=user) (samaccountname={0}))", username); directorysearcher.propertiestoload.add("msrtcsip-primaryuseraddress"); try { var result = directorysearcher.findone(); var found = false; if (result != null) { if (result.properties["msrtcsip-primaryuseraddress"] != null) { found = true; console.writeline("found: " + result.properties["msrtcsip-primaryuseraddress"][0]); } } if (!found) { console.writeline("sad face"); } } catch (exception x) { console.writeline(x.message); } console.writeline("------------"); } }
i trying figure out how format ldap connection string last week, , found entry on over serverfault:
how can figure out ldap connection string?
i noticed had "/" between each ou or dc entry - didn't include in mine, , don't see them included in above example either.
i'm far expert (obviously) figured throw out there.
Comments
Post a Comment