Skip to content

Instantly share code, notes, and snippets.

@margusmartsepp
Created May 19, 2016 13:41
Show Gist options
  • Save margusmartsepp/e1b8744891e7471e69385b2318878bd5 to your computer and use it in GitHub Desktop.
Save margusmartsepp/e1b8744891e7471e69385b2318878bd5 to your computer and use it in GitHub Desktop.
IdentityUtil
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;
}
}
@margusmartsepp
Copy link
Author

System.Environment.UserDomainName

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment