c# - Get domain chosen by PrincipalContext -
i'm creating custom login functionality asp.net validates against active directory. user must able login username or username , domain (and password in both cases).
code:
authuser user = authentication.getdomainandusername(givenusername); bool validaccount = false; principalcontext network = null; if (user.domain != "") network = new principalcontext(contexttype.domain, user.domain); else network = new principalcontext(contexttype.domain); if (userprincipal.findbyidentity(network, identitytype.samaccountname, user.username) != null) { validaccount = network.validatecredentials(givenusername, givenpassword, contextoptions.negotiate); } the "authuser" contains username and, if given, domain. if user didn't explicitly specify domain above still works fine.
so if call
new principalcontext(contexttype.domain); it seems domain set automatically.
in case, how can find out domain used?
you can domain used user principal returned userprincipal.findbyidentity()
Comments
Post a Comment