Is there any built-in utility or helper to parse HttpContext.Current.User.Identity.Name
, e.g. domain\\user
to get separately domain name if exists
Seems like a problem made to be solved by regular expressions:
public static class UserExtensions
{
public static string GetDomain(this IIdentity identity)
{
Regex.Match(identity.Name, ".*\\\\").ToString()
}
public static string GetLogin(this IIdentity identity)
{
return Regex.Replace(identity.Name, ".*\\\\", "");
}
}
System.Environment.UserDomainName
gives you the domain name only
Similarly, System.Environment.UserName
gives you the user name only