8

With the help of this blog, I have added a custom profile property OfficeKey to ApplicationUser class (in IdentityModels.cs file):

public class ApplicationUser : IdentityUser
{
      public int OfficeKey { get; set; }

      //remaining code here
}

I can get user name like this:

   User.Identity.Name

How do I get custom user data OfficeKey?

I have tried these:

How to get Identity User Data from Asp.net mvc Model

How to get user email address from ASP.NET MVC Default Mempership Model?

NB: It is an ASP.NET MVC 5 web application with MySQL membership provider.

1 Answer 1

11

If you configure the UserManager with the ApplicationUser it will return the user with the information as follows:

 // Create manager
 var manager = new UserManager<ApplicationUser>(
    new UserStore<ApplicationUser>(
        new ApplicationDbContext()))

// Find user
var user = manager.FindById(User.Identity.GetUserId());

The OfficeKey will be available in the user.

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

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.