ASP.NET核心 - 注册新用户

时间:2017-06-19 20:21:06

标签: authentication asp.net-core http-post

我在此项目之后添加了向项目添加新用户的功能:

http://www.c-sharpcorner.com/article/asp-net-core-mvc-authentication-and-role-based-authorization-with-asp-net-core/

但是,当我尝试添加新用户时遇到问题:

在UserController的Post方法:

    [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);

我在这一行收到错误:

  IdentityResult result = await userManager.CreateAsync(user, model.Password);    
       if (result.Succeeded)  

当我在这里休息时,我发现result为空。

enter image description here

我试图自己解决这个问题,但到目前为止还没有运气。

有什么想法吗?提前感谢您的帮助。

问候,

0 个答案:

没有答案