c# - 如何获取当前登录用户的详细信息?
问题描述
我添加到新属性ApplictionUser
,现在我想检索它?
public class ApplicationUser : IdentityUser
{
[Required]
[StringLength(50)]
public string FirstName { get; set; }
[Required]
[StringLength(50)]
public string LastName { get; set; }
//....
}
我试图通过使用检索,
User.Identity...
但我无法获得名字和姓氏?
怎么做 ?我将非常感激。
解决方案
我以这种方式检索了 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);
这些步骤对我有用。
推荐阅读
- reactjs - Kubernetes/Docker/Create React App + nginx 不返回静态文件?
- java - 如何在 Java 中精确计算距离?
- sql-server - SQL Server:数据库用户访问模式
- java - 组件 tJavaFlex_1(时间)中的异常 java.lang.ArrayIndexOutOfBoundsException: 1 javatflex 和 tmemorizerows
- tensorflow - Tensorflow:对 LSTM 的期望
- python - 有没有办法在不声明的情况下调用变量
- python - 应用 .nsmallest(2) 后计算 Pandas 中 Groupby 对象的平均值
- linux - 在 yocto 中设置不同任务的优先级?
- firebase - 如何从firestore子集合中获取数据
- javascript - 带有数据库内容的 javascript 参数