0

I have implemented a custom UserStoreManager and I add same custom field into ApplicationUser.

It's work fine.

Now, I have a question. How I can get the ApplicationUser custom field value from a Controller?

I find the UserId information calling User.identity.getuserid or User.identity.getuserName but how I can access to the ApplicationUser Field?

Thank you

2 Answers 2

1

You just pull the user from the database. Something like:

var user = UserManager.FindById(User.Identity.GetUserId());
Sign up to request clarification or add additional context in comments.

Comments

0

You need to get ApplicationUser first for the current user.

var currentUser = UserManager.FindById(HttpContext.User.Identity.GetUserId());
var customField = currentUser.CustomField;

private AppUserManager UserManager
{
   get { return HttpContext.GetOwinContext().GetUserManager<AppUserManager>(); }
}

2 Comments

but I do it every time?
Yes, Identity doesn't know the custom property name, so you cannot retrieve it like GetXXX.

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.