且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更新Asp.net标识中的用户属性?

更新时间:2023-02-16 16:26:08

我正在使用这个班级



  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 &GT; 跨度>


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 class

public 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>