2016-10-25 39 views
1

ASP.NET IDに特定のユーザー名とパスワードを持つユーザーが存在するかどうかを確認します。私が試したし、それは私のコードです:エンティティタイプIdentityUserは、ASP.NETの現在のコンテキストのモデルの一部ではありません。ID:

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.

あなたが私に解決策を教えてくれますか?デフォルトMVCプロジェクトを使用している場合

答えて

1

は、あなたの代わりにIdentityUserApplicationUserモデルを使用し、以下のようにコードを更新する必要があります。

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

答えを更新します。 –

関連する問題