如何在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
将是用户名。
我有一个组织的应用程序,用户将使用域用户登录到他的系统,所以现在我想获取该登录用户。我尝试了很多方法并在本地获取用户名,但我的应用程序在 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
将是用户名。