【发布时间】:2013-04-29 21:13:18
【问题描述】:
在我的 Web 应用程序中,我需要显示当前登录系统的用户名。我的表单中有一个文本框和一个按钮。示例:如果用户 "Admin" 当前已登录并使用 (本地)系统。单击按钮后,名称 Admin 必须显示在文本框中。
【问题讨论】:
标签: asp.net localsystem
在我的 Web 应用程序中,我需要显示当前登录系统的用户名。我的表单中有一个文本框和一个按钮。示例:如果用户 "Admin" 当前已登录并使用 (本地)系统。单击按钮后,名称 Admin 必须显示在文本框中。
【问题讨论】:
标签: asp.net localsystem
请尝试以下代码获取当前用户名
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
【讨论】:
嘿,请参考 Asp.Net 的代码
string currentUsername = System.Web.HttpContext.Current.User.Identity.Name;
这是经过测试的代码。
【讨论】: