简体   繁体   English

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

[英]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.

相关问题 如何在asp.net中使用Windows身份验证获取用户名? - How to get user name using Windows authentication in asp.net? 获取当前登录用户的ID ASP.NET Web Forms - Get ID of current logged in user in ASP.NET Web Forms 检索浏览我的asp.net Web应用程序的客户端的Windows用户名 - Retrieve windows user name of client who browses my asp.net web application 获取 ASP.net 应用程序记录的用户名 - Get the logged username to ASP.net application ASP.NET成员身份登录用户 - ASP.NET Membership Get logged on user 是否可以在 asp.net web 应用程序中获取客户端计算机操作系统用户名 - Is it possible to get client machine OS user name in asp.net web application 如何在ASP.NET Web应用程序中检索“登录用户”? - How can I retrieve Logged In user in an ASP.NET web application? 获取Windows用户名,而不是以ASP .NET Web窗体4.5登录用户名 - getting windows username instead of logged in user name in asp .net web form 4.5 如何通过匿名访问从ASP.NET获取Windows登录用户ID - How to get windows logged in user id from ASP.NET with anonymous access 如何在 ASP.NET Core Identity 中控制器的构造函数中获取登录用户名 - How to get logged-in user name in the constructor of a controller in ASP.NET Core Identity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM