Built-in helper to parse User.Identity.Name into Domain\Username

后端 未结 8 701
面向向阳花
面向向阳花 2020-12-02 22:23

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

8条回答
  •  感动是毒
    2020-12-02 22:52

    I think No too, because I asked myself the same question the other day :D

    You can try:

    public static string GetDomain(string s)
    {
        int stop = s.IndexOf("\\");
        return (stop > -1) ? s.Substring(0, stop + 1) : null;
    }
    
    public static string GetLogin(string s)
    {
        int stop = s.IndexOf("\\");
        return (stop > -1) ? s.Substring(stop + 1, s.Length - stop - 1) : null;
    }
    

提交回复
热议问题