本文介绍了如何更新Asp.net标识中的用户属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用此代码显示用户个人资料属性 var currentUserId = User.Identity.GetUserId(); var manager1 = new UserManager< applicationuser>( new UserStore< applicationuser>( new ApplicationDbContext())); var currentUser = manager1.FindById(User.Identity.GetUserId()); TextBox1.Text = currentUser.UserInfo.FullName; 但是如何在代码下更新用户配置文件属性不起作用 b $ b var currentUserId = User。 Identity.GetUserId(); var manager1 = new UserManager< applicationuser>( new UserStore< applicationuser>( new ApplicationDbContext())); var currentUser = manager1.FindById(User.Identity.GetUserId()); currentUser.UserInfo.FullName = TextBox1.Text; 解决方案 我正在使用这个班级 public class ApplicationUser:IdentityUser { public virtual UserInfo UserInfo {获得; set ; } } public class UserInfo { public int ID { get ; set ; } public string FullName { get ; set ; } } public class ApplicationDbContext:IdentityDbContext< ApplicationUser> { public ApplicationDbContext(): base ( AP) {} public System.Data.Entity.DbSet< UserInfo> UserInfo { get ; set ; } } 和 var manager1 = new UserManager< applicationuser>( new UserStore< applicationuser>( new ApplicationDbContext())); var currentUser = manager1.FindById(User.Identity.GetUserId()); currentUser.UserInfo.FullName = TextBox1.Text < / applicationuser > < / applicationuser > I am using this code to show user profile properties var currentUserId = User.Identity.GetUserId(); var manager1 = new UserManager<applicationuser>(new UserStore<applicationuser>(new ApplicationDbContext())); var currentUser = manager1.FindById(User.Identity.GetUserId()); TextBox1.Text = currentUser.UserInfo.FullName; But how can update user profile properties below code is not working var currentUserId = User.Identity.GetUserId(); var manager1 = new UserManager<applicationuser>(new UserStore<applicationuser>(new ApplicationDbContext())); var currentUser = manager1.FindById(User.Identity.GetUserId()); currentUser.UserInfo.FullName = TextBox1.Text; 解决方案 I am using this classpublic class ApplicationUser : IdentityUser { public virtual UserInfo UserInfo { get; set; } } public class UserInfo { public int Id { get; set; } public string FullName { get; set; } } public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("AP") { } public System.Data.Entity.DbSet<UserInfo> UserInfo { get; set; } }and var manager1 = new UserManager<applicationuser>(new UserStore<applicationuser>(new ApplicationDbContext())); var currentUser = manager1.FindById(User.Identity.GetUserId()); currentUser.UserInfo.FullName = TextBox1.Text</applicationuser></applicationuser> 这篇关于如何更新Asp.net标识中的用户属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-25 18:53