MVC5 ApplicationUser custom properties

老子叫甜甜 提交于 2019-11-30 10:04:10

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.

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.

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

public class ApplicationUser : IdentityUser
{
    public virtual Person Person { get; set; }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!