string domainAndName = User.Identity.Name; string[] infoes = domainAndName.Split(new char[1] { ‘\\‘ }, StringSplitOptions.RemoveEmptyEntries); string userDomainName = ""; string userName = ""; if (infoes.Length > 1) { userDomainName = infoes[0]; userName = infoes[1]; }
方法2:
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent()); string[] logon = wp.Identity.Name.Split(‘\\‘); string UserDomain = logon[0];//网域 string UserName = logon[1].ToString().ToLower();//登陆名