获取系统登录用户名 [英] Get system logged in username
本文介绍了获取系统登录用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了一个包含Windows身份验证的应用程序,因此不需要任何登录.直接应从登录的系统中获取系统的用户名.
我使用System.Environment.UserName在本地主机上运行时可以给我正确的用户名.
但是,当我在iis上上传它时,它为我提供了网络服务"作为用户名.
Priyanka.
Hi,
I have developed an app which contains windows authentication.so it does not need any login.Directly it should fetch the system''s username from which it has logged in.
I have used System.Environment.UserName which gives me correct username ,when i run at my localhost.
But when i upload it on iis it gives me "Network Services" as Username.
Priyanka.
推荐答案
环境.UserName [ ^ ]获取当前登录到Windows操作系统的用户的用户名-这是当前正在执行代码的安全证书的标识.
您想要的是 HttpContext.User [
Environment.UserName [^] Gets the user name of the person who is currently logged on to the Windows operating system - it''s the identification of the security credentials currently executing the code.
What you want is HttpContext.User[^] which will be the security credentials for the user executing the HTTP request.
HttpContext.Current.User.Identity.Name
试试...
try...
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
这篇关于获取系统登录用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文