TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Luis Alberto Delgado de la Flor
NA
127
23.1k
Registering New Users
Jun 19 2017 4:13 PM
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,
Reply
Answers (
4
)
How to Create html text editor by using Tiny MCE in asp.net?
Connect Asp.net Application with Sql server management 2012