从虚拟机获取用户名
Get a user name from Virtual Machine
我有一个小型 Web 应用程序,目前托管在虚拟机中。机器有 Windows 8 + IIS 7。
作为应用程序的一部分,我需要获取访问该该死的 Web 应用程序的用户的用户名。但是每次我尝试获取当前用户时,我总是会获取虚拟机名称。
如何正确获取访问该应用程序的机器名称。在虚拟机上?
在控制器上,无论是 Windows 还是 Forms Auth,您都应该能够通过以下方式获取用户:
this.User.Identity.Name
或来自 HTTP 上下文:
HttpContext.Current.User.Identity.Name
如果用户通过 Active Directory 登录,这应该有效:
System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;
我有一个小型 Web 应用程序,目前托管在虚拟机中。机器有 Windows 8 + IIS 7。
作为应用程序的一部分,我需要获取访问该该死的 Web 应用程序的用户的用户名。但是每次我尝试获取当前用户时,我总是会获取虚拟机名称。
如何正确获取访问该应用程序的机器名称。在虚拟机上?
在控制器上,无论是 Windows 还是 Forms Auth,您都应该能够通过以下方式获取用户:
this.User.Identity.Name
或来自 HTTP 上下文:
HttpContext.Current.User.Identity.Name
如果用户通过 Active Directory 登录,这应该有效:
System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;