2016-04-05 20 views
0

'FindByEmail'メソッドを有効にするにはどうすればいいですか? ASP.netFindByEmailがasp.netにありません

私はasp.netで

ファイルRoleActions.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
... 
using Microsoft.AspNet.Identity; 
using Microsoft.AspNet.Identity.EntityFramework; 

... 
      IdentityResult IdRoleResult; 
      IdentityResult IdUserResult; 

      //Create a Role object by using the ApplicationDbContext object. 
      // The RoleStore is only allowed to contain IdentityRole objects. 
      var roleStore = new RoleStore<IdentityRole>(context); 

      //Create a RoleManager object that is only allowed to contain IdentityRole objects. 
      //When creating the RoleManager object, you pass in (as a parameter) a new RoleStore object. 
      var roleMgr = new RoleManager<IdentityRole>(roleStore); 

      //Then, you create the "canEdit" role if it doesn't already exist. 
      if (!roleMgr.RoleExists("canEdit")) 
      { 
       IdRoleResult = roleMgr.Create(new IdentityRole { Name = "canEdit" }); 
      } 

      // Create a UserManager object based on the UserStore object and the ApplicationDbContext object. Note that you can create new objects and use the as parameters in a single line of code, rather than using multiple lines of code, as you did for the RoleManager object. 

      var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context)); 
      var appUser = new ApplicationUser 
      { 
       UserName = "[email protected]", 
       Email = "[email protected]" 
      }; 
      IdUserResult = userMgr.Create(appUser, "password1"); 

      // If the new "canEdit" user was successfully created, add the "canEdit" user to the "canEdit" role. 
      if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "canEdit")) 
      { 
       IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "canEdit"); 
      } 
     } 
    } 
} 

ファイルIdentityModels.cs私が手

// You can add User data for the user by adding more properties to your User class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. 
public class ApplicationUser : IdentityUser 
{  
} 

を次のコードを持っていますビルド時のエラー:

「エラー1 『Microsoft.AspNet.Identity.UserManager < .... ApplicationUser>』 'のタイプ の最初の引数を受け入れる 『FindByEmail』と拡張子なし 方法 『FindByEmail』の定義が含まれていません。 Microsoft.AspNet.Identity.UserManager < .... ApplicationUser>」(あなたがusingディレクティブまたはアセンブリ参照 不足している?)が見つかり 可能性が...」

答えて

関連する問題