我正在尝试遵循本教程,但我陷入了它尝试添加基于 ApplicationUser 的代码的区域。角色部分。
dotnet deploy db based MVC site to azure
我确实包含了这些行:
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
我的编译错误
错误 1 找不到类型或命名空间名称“ApplicationUser”(您是否缺少 using 指令或程序集引用?) c:\users\blah\documents\visual studio 2013\Projects\blah\等等\Migrations\Configuration.cs 96 38 等等
编辑: 这是完整的代码片段:
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;
}
最佳答案
您是否创建了一个继承自IdentityUser的ApplicationUser类?如果是,您是否将 ApplicationUser 类所在的命名空间添加到 Configuration 类中?
这是解决此错误的最合理的方法。
关于asp.net-mvc - ApplicationUser - 我如何使用它?我需要在 using 子句中添加什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21502196/