C# asp.net中缺少FindByEmail
如何在ASP.net中启用方法“FindByEmail”? 我在asp.net中有以下代码 文件RoleActions.csC# asp.net中缺少FindByEmail,c#,asp.net,entity-framework,asp.net-identity,C#,Asp.net,Entity Framework,Asp.net Identity,如何在ASP.net中启用方法“FindByEmail”? 我在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; ...
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 = "canEditUser@example.com",
Email = "canEditUser@example.com"
};
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("canEditUser@example.com").Id, "canEdit"))
{
IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("canEditUser@example.com").Id, "canEdit");
}
}
}
}
// 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'
不包含“FindByEmail”的定义且没有扩展名
方法“FindByEmail”接受类型为的第一个参数
“Microsoft.AspNet.Identity.UserManager”可以是
找到(是否缺少using指令或程序集
参考?“…”
FindByEmail是在ASP.NET Identity 2.0中添加的(请参见声明) 让FindByEmail安装最新的软件包
- Microsoft.AspNet.Identity.EntityFramework
- Microsoft.AspNet.Identity.Core
- Microsoft.AspNet.Identity.OWIN