【发布时间】:2018-12-17 14:57:55
【问题描述】:
例如:
我有一个简单的应用程序!
并且默认实现了简单的用户注册页面和登录页面(当我们选择mvc tempate时)。
所以我为用户注册模型添加了新属性。 像这样。
public class ApplicationUser : IdentityUser
{
[Required]
[StringLength(255)]
public string FirstName { get; set; }
[Required]
[StringLength(50)]
public string LastName { get; set; }
[Required]
[StringLength(10)]
public string Gender { get; set; }
[Required]
[StringLength(50)]
public UserType UserType { get; set; }
[Required]
[StringLength(255)]
public Department Depatment{ get; set; }
[Required]
[StringLength(50)]
public Session Session { get; set; }
}
这些属性也被添加到RegisterViewModel中,用于渲染注册页面等等..
问题:
当新用户注册时!并登录应用程序。 所以现在我想访问登录的用户详细信息? 即名字、姓氏、性别等。
我试过User.Identity.?,但没有这样的属性?之前我添加到 ApplicationUser ?
我想访问所有 LoggedIn 用户属性并将其呈现在视图中。
[Authorize]
public ActionResult Index()
{
// Retreiving LoggedIn User Details.
// ....
// ....
// LoggedInUserInfo = // assigning all the User details to the LoggedUserInfo
return View(LoggedInUserInfo); // LoggedInUserInfo is a separete class that having several properties such as firstName, lastName, Gener, etc...
}
【问题讨论】:
-
你的“ApplicationUser”在哪里被持久化了?
-
~/Models/IdentityModels.cs在 identity.cs 文件中
标签: c# asp.net-mvc asp.net-identity