实体类型IdentityUser不是ASP.NET Identity中当前上下文的模型的一部分 [英] The entity type IdentityUser is not part of the model for the current context in ASP.NET Identity

查看:98
本文介绍了实体类型IdentityUser不是ASP.NET Identity中当前上下文的模型的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查ASP.NET Identity中是否存在具有特定用户名和密码的用户.我试过了,这就是我的代码:

I want to check if there is a user with particular username and password in ASP.NET Identity. I tried and that is my code:

UserManager<IdentityUser> userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(new ApplicationDbContext()));
var user = await userManager.FindAsync(userName, password);

但是,出了点问题,那就是错误:

However, something goes wrong and that is the error:

实体类型IdentityUser不是当前模型的一部分 上下文.

The entity type IdentityUser is not part of the model for the current context.

您能告诉我解决方案吗?

Would you tell me a solution?

推荐答案

如果使用默认的MVC项目,则必须使用ApplicationUser模型而不是IdentityUser并按如下所示更新代码:

If you are using default MVC project you have to use ApplicationUser model instead of IdentityUser and update your code as follow:

  public async Task<ViewResult> Index()
    {
        UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
        var user = await userManager.FindAsync("UserName", "Password");
        return View(user);
    }

这篇关于实体类型IdentityUser不是ASP.NET Identity中当前上下文的模型的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆