c# - Get Clients Current Domain Controller -
i'm trying domain controller client machine of asp.net
application connected using c#
.
the application intranet application never exposed internet , every user using application must authenticated through windows. therefore means user connected domain controller in our corporate network.
i've tried using following code returning domain controller iis server connected to:
using system.directoryservices; public static string getdc() { directoryentry entry = new directoryentry("ldap://rootdse"); return entry.properties["dnshostname"].value.tostring(); }
i've read several other questions on matter seem produce iis servers domain controller.
my question whether possible obtain clients connected domain controller , if so, how?
a couple of things active directory authentication:
- users don't connect domain controller. authenticated against active directory, distributed service hosted 1 or many domain controllers replicate information amongst 1 another
- when user authenticated web application, iis performs authentication. 401 challenge issued, , user's machine supplies credentials in form of token. iis uses token authenticate, authorize, , identify user
- a web application user authenticated windows authentication represented on server windowsidentity object. windowsidentity object contains few properties, none of expose underlying ad information (other domain/username)
- client-side code (aka javascript) not going have access sensitive ad information on machine. bad if did.
if want details on how authentication works in ad, have here: https://technet.microsoft.com/en-us/library/cc780332(v=ws.10).aspx
now, if users on different domains, can domain user's username , use perform ad lookups.
string usernamewithdomain = httpcontext.current.user.identity.name; // returns somedomain\username
you split on '\' , take first element.
Comments
Post a Comment