简体   繁体   English

如何在Windows中获得当前用户?

[英]How can I get current user in windows?

I have a web program In asp.net and c#. 我在asp.net和c#中有一个Web程序。 In my application I want get the current windows username and save it on a variable.If I run my app in local I can do it easily but when I run my app from server How can I do it? 在我的应用程序中,我想获取当前的Windows用户名并将其保存在变量中。如果我在本地运行我的应用程序,我可以很容易地做到这一点,但是当我从服务器运行我的应用程序时该怎么办呢? It means How can I get current user from HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows \\CurrentVersion\\ Authentication /LogonUI and save it on a variable? 这意味着我如何从HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Authentication / LogonUI获取当前用户并将其保存在变量中?

You cannot do this. 你不可以做这个。 You cannot get the logon username of the computer that the web browser is running on. 您无法获取正在运行Web浏览器的计算机的登录用户名。 And for good reasons, you would read data that you have no business reading. 出于充分的原因,您会读取没有业务需求的数据。 If you need that username, have the user enter it. 如果您需要该用户名,请让用户输入。

in c# you can get the windows identity by string variable = System.Environment.UserName 在C#中,您可以通过字符串变量= System.Environment.UserName来获取Windows身份

i hope this helped. 我希望这会有所帮助。

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

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