MVC5 ApplicationUser custom properties

前端 未结 3 1754
野的像风
野的像风 2021-01-01 01:55

I am trying to get to grips with the new Membership system introduced in ASP.NET MVC 5 and I\'ve come across a small issue which I am pretty sure you will be able to help me

相关标签:
3条回答
  • 2021-01-01 02:35

    Mark the Person object as virtual in your ApplicationUser definition. That worked for me.

    public class ApplicationUser : IdentityUser
    {
        public virtual Person Person { get; set; }
    
    0 讨论(0)
  • 2021-01-01 02:42

    Explore IdentityManager.Store.UserManagement and IdentityManager.Store.Users.

    ApplicationUser cUser = (ApplicationUser) await IdentityManager.Store.Users.FindByNameAsync(HttpContext.User.Identity.Name, new System.Threading.CancellationToken());
    cUser.Surname = "New Something";
    IdentityResult result1 = await IdentityManager.Store.SaveChangesAsync();
    

    Above code is an example only. Basically you need to explore the Store property of IdentityManage.

    0 讨论(0)
  • 2021-01-01 02:43

    When we used the Users object of our database context we ran into other tracking errors. In our application, we would retrieve users as such

    var user = UserManager.FindById(userId);
    

    Edit the properties:

    user.StorageName = "gooblygook";
    //whatever other properties you would like to use
    

    And then we would save it with the UserManager in the controller:

    UserManager.Update(user);
    

    This is currently a working solution for us.

    0 讨论(0)
提交回复
热议问题