The Errormessage is this:
The path /account/register threw an exception System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.IUserStore1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'Microsoft.AspNetCore.Identity.UserManager
1[Microsoft.AspNetCore.Identity.
I can't figure out what causes this. Any help is greatly appreciated, thank you!
public class AccountController : Controller
{
private readonly UserManager<IdentityUser> userManager;
private readonly SignInManager<IdentityUser> signInManager;
public AccountController(UserManager<IdentityUser> userManager,
SignInManager<IdentityUser> signInManager)
{
this.userManager = userManager;
this.signInManager = signInManager;
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public async Task<IActionResult> Register(RegisterViewModel model)
{
if(ModelState.IsValid)
{
var user = new IdentityUser { UserName = model.Email, Email = model.Email };
var result = await userManager.CreateAsync(user, model.Password);
if(result.Succeeded)
{
// Persistend creates either session or permanent cookie
await signInManager.SignInAsync(user, isPersistent: false);
return RedirectToAction("index", "home");
}
foreach (var error in result.Errors)
{
// Adding this to Modelstate goes to validation-summary in register.cshtml
ModelState.AddModelError("", error.Description);
}
}
return View(model);
}
}