사용자 관리를 위해 MVC5에서 코드를 처음 사용합니다. 비밀번호를 변경할 수는 있지만 사용자 등록을 업데이트 할 수 없습니다. 나는 인터넷을 샅샅이 뒤지고이 사이트에서 UserManager.Update (사용자)와 관련된 모든 질문을 문자 그대로 보지 않습니다.MVC5 Identity UserManager.Update (user) not working
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
namespace _100..Models
{
public class ApplicationUser : IdentityUser
{
public virtual PersonalInfo PersonalInfo { get; set; }
public virtual BillingInfo BillingInfo { get; set; }
public virtual DeliveryInfo DeliveryInfo { get; set; }
public Chapters Chapter { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class PersonalInfo
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class BillingInfo
{
public int ID { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
public class DeliveryInfo
{
public int ID { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false){}
public DbSet<PersonalInfo> PersonalInfo { get; set; }
public DbSet<BillingInfo> BillingInfo { get; set; }
public DbSet<DeliveryInfo> DeliveryInfo { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
}
그리고 여기 내가이 작업을 명중하고 업데이트 방법은 성공을 반환 할 때 사용자 개체가 업데이트 된 데이터를 가지고 있음을 확인했다
[HttpPost]
public async Task<ActionResult> UpdateRegisteration(ApplicationUser user)
{
var result = await UserManager.UpdateAsync(user);
return RedirectToAction("Index", "Home");
}
내 행동입니다하지만 실제로 데이터베이스를 업데이트하지 않습니다.
'UserManager' 선언을 게시 할 수 있습니까? 'DbContext'는이'UserManager'를 사용합니까? – Ofiris
내 AccountController의 생성자로 전달됩니다. '코드'public AccountController (ApplicationUserManager userManager, ApplicationSignInManager signInManager) { UserManager = userManager; SignInManager = signInManager; } – Nayls
그리고 어디서 만들어 졌습니까? – Ofiris