繁体   English   中英

使用asp.net Web应用程序获取用户登录窗口的名称

[英]get name of User logged into windows using asp.net web application

当我使用System.Environment.UserName或httpcontext.current ....等所有返回“系统”作为用户,因为我的网站托管在系统特权。 试过WMI,但这个空洞。

ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem");
ManagementObjectCollection collection = searcher.Get();
WinUser = (string)collection.Cast<ManagementBaseObject>().First()["UserName"];

我正在使用基本身份验证并关闭匿名身份验证。 任何想法?

在客户端计算机上找到登录用户本身是不可能的,特别是如果客户端计算机是iPad。

您可以使用HttpContext.Current.User获取从基本身份验证中收到的用户名。

除非这是一个Intranet应用程序并且您正在使用Windows身份验证,否则无法在未先提示用户输入凭据的情况下获取此信息。

假设您正在使用Windows身份验证,并且您的用户在提示时输入其网络凭据,您应该能够获得如下的用户名:

string userName = Page.User.Identity.Name;

尝试HttpContext.Current.Request.LogonUserIdentity

暂无
暂无

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

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