我正在尝试按照本教程,但我陷入了尝试添加基于ApplicationUser的代码的区域。角色部分。
dotnet deploy db based MVC site to azure
我确实包含了这些内容:
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
我的编译错误
Error 1 The type or namespace name 'ApplicationUser' could not be found (are you missing a using directive or an assembly reference?) c:\users\blah\documents\visual studio 2013\Projects\blah\blah\Migrations\Configuration.cs 96 38 blah
修改: 这是整段代码:
bool AddUserAndRole(ContactManager.Models.ApplicationDbContext context)
{
IdentityResult ir;
var rm = new RoleManager<IdentityRole>
(new RoleStore<IdentityRole>(context));
ir = rm.Create(new IdentityRole("canEdit"));
var um = new UserManager<ApplicationUser>(
new UserStore<ApplicationUser>(context));
var user = new ApplicationUser()
{
UserName = "user1",
};
ir = um.Create(user, "Passw0rd1");
if (ir.Succeeded == false)
return ir.Succeeded;
ir = um.AddToRole(user.Id, "canEdit");
return ir.Succeeded;
}
答案 0 :(得分:11)
您是否创建了一个继承自 IdentityUser 的 ApplicationUser 类?如果是这样,您是否将 ApplicationUser 类所在的命名空间添加到配置类?
这是解决此错误最合理的事情。