[英]get name of User logged into windows using asp.net web application
When I use System.Environment.UserName or httpcontext.current.... etc all are returning "System" as user as my site is hosted in system privileged. 当我使用System.Environment.UserName或httpcontext.current ....等所有返回“系统”作为用户,因为我的网站托管在系统特权。 Tried WMI but this comes up as empty.
试过WMI,但这个空洞。
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem");
ManagementObjectCollection collection = searcher.Get();
WinUser = (string)collection.Cast<ManagementBaseObject>().First()["UserName"];
I am using Basic Authentication and Anonymous authentication is turned off. 我正在使用基本身份验证并关闭匿名身份验证。 any idea?
任何想法?
It is inherently impossible to find out the logged-in user on the client computer, especially if the client computer is an iPad. 在客户端计算机上找到登录用户本身是不可能的,特别是如果客户端计算机是iPad。
You can get the username received from basic auth using HttpContext.Current.User
. 您可以使用
HttpContext.Current.User
获取从基本身份验证中收到的用户名。
Unless this is an intranet application and you're using Windows Authentication, there is no way to get this information without first prompting the user for their credentials. 除非这是一个Intranet应用程序并且您正在使用Windows身份验证,否则无法在未先提示用户输入凭据的情况下获取此信息。
Assuming that you are using Windows Authentication and your users are entering their network credentials when prompted, you should be able to get the username like this: 假设您正在使用Windows身份验证,并且您的用户在提示时输入其网络凭据,您应该能够获得如下的用户名:
string userName = Page.User.Identity.Name;
尝试HttpContext.Current.Request.LogonUserIdentity
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.