How do I get a custom field in the aspnetusers table?

Using the CodeFirst migration, I added a custom Lastname field to the aspnetusers table in the standard db in the asp mvc template in VS 2013 (sorry for the "in"). How do I get the value for the Last Name field if I'm signed in?

+3


source to share


2 answers


In any action method, you can get the current user ID by calling the extension method User.Identity.GetUserId()

. And you can get more information using ApplicationUserManager

this:

public ActionResult MyAction()
{
    string surname = HttpContext.GetOwinContext()
        .GetUserManager<ApplicationUserManager>()
        .FindById(User.Identity.GetUserId()).Surname;
}

      



Make sure you add a namespace Microsoft.AspNet.Identity.Owin

to use the extension method.

+5


source


Do you have a custom custom class? If yes ... so "Lastname" will only be one of the properties of the user class (be sure to set PUBLIC)



if you just change TABLE IN DATABASE you can get this property because id doesn't know what this column is because you don't have any class with this structure

0


source







All Articles