2016-10-25 23 views
1

我想檢查在ASP.NET身份中是否存在具有特定用戶名和密碼的用戶。我想,這是我的代碼:實體類型IdentityUser不是ASP.NET身份中當前上下文的模型的一部分

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

然而,不順心的事,那就是錯誤:

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

你能告訴我一個解決方案嗎?

回答

1

如果使用默認的MVC項目,你必須使用ApplicationUser模型而不是IdentityUser和更新您的代碼如下:

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); 
    } 
+0

我的工作,但現在我還有一個問題。 FindAsync函數不響應 –

+0

我更新答案 –

相關問題