Using CodeFirst migration, i added custom field "Surname" in table aspnetusers in standart db in asp mvc template in VS 2013(sorry for "in"). How get value of "Surname" field, if i logged in?
2 Answers
In any action method you could get current user id by calling User.Identity.GetUserId() extension method. And you could get extra information by make use of ApplicationUserManager like this:
public ActionResult MyAction()
{
string surname = HttpContext.GetOwinContext()
.GetUserManager<ApplicationUserManager>()
.FindById(User.Identity.GetUserId()).Surname;
}
Make sure you added Microsoft.AspNet.Identity.Owin namespace to could use the extension method.
1 Comment
AccountDisabled Boolean on ApplicationUser. This allowed me to check what that Boolean was set to.Did you have your custom class user? If yes......so "Surname" just will one of user class properties (sure you need set PUBLIC)
if you just change TABLE Into Database you can get this property, because identity don't know what is this column, because you don't have any class with this structure