繁体   English   中英

如何在mvc中获取本地系统域的当前登录用户

[英]How to get current logged in user of Domain of local system in mvc

我有一个组织的应用程序,用户将使用域用户登录到他的系统,所以现在我想获取该登录用户。 我尝试了很多方法并在本地获取用户名,但我的应用程序在 IIS 上,它使用IIS APPPool\DefaultAppPool获取 IIS 用户,而系统名称和域却没有。

这是我用来获取用户名的代码:

Request.ServerVariables.Get("logon_user");
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Environment.GetEnvironmentVariable("USERNAME");
System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;

如果有人知道如何获取本地用户名而不是 IIS,请分享。 提前致谢。

如果您有 Windows 身份验证工作,那么当前用户在HttpContext.User中可用。

User.Identity.Name将是用户名。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM