我向 ApplictionUser
添加了新属性,现在我想检索它?
public class ApplicationUser : IdentityUser
{
[Required]
[StringLength(50)]
public string FirstName { get; set; }
[Required]
[StringLength(50)]
public string LastName { get; set; }
//....
}
I tried to retrieved by using
User.Identity...
but i can't get first&last names?
怎么做?我将非常感激。
最佳答案
我以这种方式检索了 firstName 和 SecondName:
第 1 步。
// DbContext.
private readonly ApplicationDbContext _context;
public HomeController()
{
_context = new ApplicationDbContext();
}
第 2 步。
// Getting Id of Current LoggedIn User.
var UserId = User.Identity.GetUserId();
第 3 步。
var User = _context.Users.Single(user => user.Id == UserId);
These steps worked for me.
关于c# - 如何获取当前登录用户的详细信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54616897/