【问题标题】:Get the local system's user name获取本地系统的用户名
【发布时间】:2013-04-29 21:13:18
【问题描述】:

在我的 Web 应用程序中,我需要显示当前登录系统的用户名。我的表单中有一个文本框和一个按钮。示例:如果用户 "Admin" 当前已登录并使用 (本地)系统。单击按钮后,名称 Admin 必须显示在文本框中。

【问题讨论】:

标签: asp.net localsystem


【解决方案1】:

请尝试以下代码获取当前用户名

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

【讨论】:

    【解决方案2】:

    嘿,请参考 Asp.Net 的代码

    string currentUsername = System.Web.HttpContext.Current.User.Identity.Name;
    

    这是经过测试的代码。

    【讨论】:

      猜你喜欢
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      相关资源
      最近更新 更多