小编Min*_*nus的帖子

UserManager.FindAsync始终返回null

我在a上有以下登录操作,UserManager.FindAsync始终返回null.我试图用底部显示的代码为用户播种.

有人可以帮忙吗?

    public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (ModelState.IsValid)
        {
            var user = await UserManager.FindAsync(model.Email, model.Password);
            if (user != null)
            {
                await SignInAsync(user, model.RememberMe);
                return RedirectToLocal(returnUrl);
            }
            else
            {
                ModelState.AddModelError("", "Invalid username or password.");
            }
        }

        // If we got this far, something failed, redisplay form
        return View(model);
    }
Run Code Online (Sandbox Code Playgroud)

我在迁移下的Configuration.cs中有以下代码.它的作用是为我尝试使用上面的代码登录的用户播种.

    protected override void Seed(Temps.Models.ApplicationDbContext context)
    {
        if (!context.Roles.Any(r => r.Name == "Consultant"))
        {
            var store = new RoleStore<IdentityRole>(context);
            var manager = new RoleManager<IdentityRole>(store);
            var role = new …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-identity

2
推荐指数
1
解决办法
6631
查看次数

标签 统计

asp.net-identity ×1

asp.net-mvc ×1