User.Identity.Name全名mvc5 [英] User.Identity.Name full name mvc5
问题描述
我在这是从 IdentityUser
ApplicationUser 类添加几个字段扩展ASP NET架构的身份>。一,我已经添加的字段是全名
。
I've extended the ASP NET identity schema by adding few fields in the ApplicationUser
Class which is derived from IdentityUser
. One of the field that I've added is FullName
.
现在,当我写 User.Identity.Name
,它给我的用户名,我正在寻找类似 User.Identity。全名
这应该返回我已经加入了全名。
Now, when I write User.Identity.Name
, it gives me the user name, I m looking for something like User.Identity.FullName
which should return the FullName that I have added.
不知道,这可怎么实现的任何指导应大大AP preciated。
Not sure, how this can be achieved any guidance shall be greatly appreciated.
感谢。
推荐答案
您可以把它当您创建用户添加到用户的要求,然后检索它从User.Identity索赔:
You could add it to the User's claims when you create the user and then retrieve it as a claim from the User.Identity:
await userManager.AddClaimAsync(user.Id, new Claim("FullName", user.FullName));
Retreive是:
Retreive it:
((ClaimsIdentity)User.Identity).FindFirst("FullName")
或者你可以只提取用户和访问它关闭直接user.FullName的:
Or you could just fetch the user and access it off of the user.FullName directly:
var user = await userManager.FindById(User.Identity.GetUserId())
return user.FullName
这篇关于User.Identity.Name全名mvc5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!