【问题标题】:ASP.NET User IdentityASP.NET 用户身份
【发布时间】:2016-01-03 05:12:20
【问题描述】:

Environment.UserName 和有什么区别?和System.Security.Principal.WindowsIdentity.GetCurrent().Name;和HttpContext.Current.User

据我了解HttpContext.Current.User 返回登录用户,System.Security.Principal.WindowsIdentity.GetCurrent().Name 返回运行代码的身份。但是Environment.UserName有什么用; ?

【问题讨论】:

标签: asp.net identity


【解决方案1】:

Environment.UserName 仅返回登录到 Windows 操作系统用户的用户名字符串 - 即“JohnDoe”

System.Security.Principal.WindowsIdentity.GetCurrent().Name 返回登录到 Windows 操作系统用户的 NetBIOS 用户名 - 即“Fabrikam\JohnDoe”

HttpContext.Current.User 返回登录到网站用户的用户对象,假设网站正在利用会员系统。要获取用户名字符串,您需要浏览 Identity 属性:

string userName = HttpContext.Current.User.Identity.Name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-19
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    • 2010-09-16
    • 2019-03-25
    • 2013-08-29
    相关资源
    最近更新 更多