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<IActionResult> 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)
When I put a break here, I see that
result is null.
I'm trying to solve it on my own but no luck so far.
Any ideas? Thanks in advance for any help.
Regards,