Identity の使用に関するドキュメントに従っており、新しいユーザーを登録しようとしています (登録アクションを実行しています) が、次のエラーで失敗します:
InvalidOperationException: このタイプはコンテキストのモデルに含まれていないため、'ApplicationUser' の DbSet を作成できません。
起動:
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
//password options
options.Password.RequireDigit = false;
// ...
})
私は標準の ApplicationUser を使用しています:
public class ApplicationUser : IdentityUser
{
}
AccountController にアクションを登録します。
public async Task<IActionResult> Register(RegisterViewModel viewModel)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = viewModel.UserName, Email = viewModel.Email };
var result = await _userManager.CreateAsync(user, viewModel.Password); //<-- Exception happens here
if (result.Succeeded)
{
await _signInManager.SignInAsync(user, isPersistent: false);
_logger.LogInformation(3, "User created a new account with password.");
return RedirectToAction(nameof(HomeController.Index), "Home");
}
string errorData = "";
foreach (var error in result.Errors)
{
errorData += error.Description + '\n';
}
StoreErrorMessage("Failed to create the user!", errorData);
}
return View(viewModel);
}
私はすでに次のことを試しました:
DbSet<ApplicationUser>
に追加AplicationContext
- 新しい移行を作成して適用しました
dotnet ef