如何使用Environment.username属性获取用户名 [英] How to get the username using Environment.username Property

查看:690
本文介绍了如何使用Environment.username属性获取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在我的应用程序中,我使用Environment.username属性获取Windows登录用户名。如果我执行应用程序并检查它,则将用户名正确地命名为Admin。发布应用程序并检查后,将用户名命名为IN $。系统用户名为IN\Admin。我只需要用户名为Admin。如何使用此Environment.Username属性获取用户名。



谢谢

解决方案

。系统用户名是IN\Admin。我只需要用户名为Admin。如何使用此Environment.Username属性获取用户名。



谢谢


试试这个:

 System.Environment.GetEnvironmentVariable(Username,EnvironmentVariableTarget.Machine))





 System.Security.Principal.WindowsIdentity.GetCurrent()。姓名





 Guid guid =( GUID)Membership.GetUser()ProviderUserKey; 


Hi,

In my Application I am using the Environment.username property for getting the windows login username. If I execute the Application and checked it gives the username correctly as "Admin". After I publish the Application and checked it give the Username as IN$.The System username is IN\Admin. I need to get only the username as "Admin". How to get the username by using this Environment.Username Property.

Thanks

解决方案

.The System username is IN\Admin. I need to get only the username as "Admin". How to get the username by using this Environment.Username Property.

Thanks


Try this:

System.Environment.GetEnvironmentVariable("Username",EnvironmentVariableTarget.Machine))


or

System.Security.Principal.WindowsIdentity.GetCurrent().Name


or

Guid guid = (Guid)Membership.GetUser().ProviderUserKey;


这篇关于如何使用Environment.username属性获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆