3

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?

1
  • Can you post your code? Commented Aug 6, 2015 at 20:02

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, goodness. This is what finally allowed me to check the value of a custom property on another user’s account. I needed a way to see if a user’s account was disabled before letting another user interact with them, and I had an AccountDisabled Boolean on ApplicationUser. This allowed me to check what that Boolean was set to.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.