c# - LDAP Pass authentication to PrincipalContext when looking up groups -


i have following code works fine when machine member of domain , logged in, doesn't work when i'm using pc isn't on domain. know users username , password authenticate using pc.validatecredentials before hand. however, code doesn't work when pc they're using isn't member of domain. how pass in user credentials code?

public list<string> getgroupnames(string username) {     var pc = new principalcontext(contexttype.machine, "dcserver01");      var src = userprincipal.findbyidentity(pc, username).getgroups(pc);     var result = new list<string>();     src.tolist().foreach(sr => result.add(sr.samaccountname));     return result; } 

the above code falls on over access denied on principal context

thanks

principalcontext provides constructor specifying username , password. msdn

public list<string> getgroupnames(string username) {     using (var pc = new principalcontext(contexttype.domain, "dcserver01", authenticatedusername, password)     {         var src = userprincipal.findbyidentity(pc, username).getgroups(pc);         var result = new list<string>();         src.tolist().foreach(sr => result.add(sr.samaccountname));         return result;     } } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -