【发布时间】:2017-06-17 08:55:14
【问题描述】:
我想在 _LoginPartial 中的导航栏中显示用户的名称,而不是用户名。目前我使用User.Identity.GetUserName() 作为用户名,但现在我想显示当前用户的名称。
_LoginPartial 由 Startup.Auth.cs 调用,因此我无法在后端运行查询并获取用户名,因此我只能使用 razor 视图中可以运行的内置函数。
我已经尝试了所有这些,但它们都给了我用户名而不是用户名。
<small>@System.Threading.Thread.CurrentPrincipal.Identity.Name</small>
<small>@User.Identity.Name</small>
<small>@threadPrincipal.Identity.Name</small>
<small>@System.Web.HttpContext.Current.User.Identity.Name</small>
如何获取名称而不是用户名
这是用户表
ID
Email
EmailConfirm
Password
Security
PhoneNumber
PhoneNumberConfirm
TwoFactorEnable
LockoutEndDateUtc
LockoutEnable
AccessFailedCount
UserName
Name
Status
Image
【问题讨论】:
-
问题解决了吗?
-
还在努力解决。
标签: asp.net-mvc razor view asp.net-identity