如何使用C#代码从Windows Active Directory获取当前用户的登录名?
发布于 2012-06-04 15:16:09
简单地说,
string Name = new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;
或
string Name = System.Environment.UserName
或
string Name = Environment.GetEnvironmentVariable("USERNAME");
或
string Name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
作品:)
发布于 2015-10-01 13:43:04
System.DirectoryServices.AccountManagement.UserPrincipal.Current.Name
这对我也很有效!谢谢
发布于 2019-11-13 23:27:16
在我看来,这对我来说是完美的!
<h5 class="mb-0 text-gray-800">Welcome, <span style="text-transform:capitalize">@User.Identity.Name.Replace("AD-GROUP-NAME\\", "").Replace(".", " ")</span></h5>
https://stackoverflow.com/questions/10877614
复制相似问题