Reputation: 13
My user id is as following Domain Name /User Id
I am able to get User Id using Userprincipal.current.Name .
How do I get the domain name from active directory
Upvotes: 0
Views: 1271
Reputation: 322
string domainName;
domainName = System.Environment.UserDomainName;
The System namespace contains fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.
The Environment Provides information about and means to manipulate, the current environment and platform. This class cannot be inherited.
The Domain account credentials for a user are formatted as the user's domain name, the '\' character, and username. Use the UserDomainName property to obtain the user's domain name without the username, and the UserName property to obtain the username without the domain name. For example, if a user's domain name and username are CORPORATENETWORK\john, the UserDomainName property returns "CORPORATENETWORK". The UserDomainName property first attempts to get the domain name component of the Windows account name for the current user. If that attempt fails, this property attempts to get the domain name associated with the username provided by the UserName property. If that attempt fails because the host computer is not joined to a domain, then the host computer name is returned.
“Developer.microsoft.com.” Learn to Develop with Microsoft Developer Network | MSDN, msdn.microsoft.com/en-us/dn308572.aspx.
Upvotes: 1