Hello,
I'm adding the functionality of adding new users to my project following this project:
http://www.c-sharpcorner.com/article/asp-net-core-mvc-authentication-and-role-based-authorization-with-asp-net-core/
However, I encounter a problem when I try to Add a new user:
On the Post Method of the UserController:
- [HttpPost]
- public async Task
AddUser(UserViewModel model) - {
- if (ModelState.IsValid)
- {
- ApplicationUser user = new ApplicationUser
- {
- Name = model.Name,
- UserName = model.UserName,
- Email = model.Email
- };
- IdentityResult result = await userManager.CreateAsync(user, model.Password);
- if (result.Succeeded)
- {
- ApplicationRole applicationRole = await roleManager.FindByIdAsync(model.ApplicationRoleId);
- if (applicationRole != null)
- {
- IdentityResult roleResult = await userManager.AddToRoleAsync(user, applicationRole.Name);
- if (roleResult.Succeeded)
- {
- return RedirectToAction("Index");
- }
- }
- }
- }
- return View(model);
- }
I'm getting an error on this line:
- IdentityResult result = await userManager.CreateAsync(user, model.Password);
- if (result.Succeeded)

I'm trying to solve it on my own but no luck so far.
Any ideas? Thanks in advance for any help.
Regards,
Nilesh ShahPosted Jun 19, 2017, 4:35 PM
Nilesh ShahPosted Jun 19, 2017, 5:04 PM
Luis Alberto Delgado de la FlorPosted Jun 19, 2017, 4:57 PM
Luis Alberto Delgado de la FlorPosted Jun 19, 2017, 4:40 PM
/Views/User/AddUser.cshtml
/Views/Shared/AddUser.cshtml"