Created
May 19, 2016 13:41
-
-
Save margusmartsepp/e1b8744891e7471e69385b2318878bd5 to your computer and use it in GitHub Desktop.
IdentityUtil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class IdentityUtil | |
{ | |
public static string GetCurrentIdentityDomainName() | |
{ | |
var identity = WindowsIdentity.GetCurrent(); | |
if (identity == null || !identity.IsAuthenticated || identity.IsSystem) | |
return null; | |
return GetDomainName(identity.Name); | |
} | |
public static string GetDomainName(string fullUserName) | |
{ | |
if (fullUserName == null) | |
return null; | |
var index = fullUserName.IndexOf("\\", StringComparison.Ordinal); | |
if (index == -1) | |
return null; | |
var domain = fullUserName.Substring(0, index); | |
return domain; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
System.Environment.UserDomainName