Asp.net-Mvc

ApplicationUser - 我如何使用它?我需要在 using 子句中添加什麼?

  • August 2, 2017

我正在嘗試遵循本教程,但我被困在嘗試添加基於 ApplicationUser 的程式碼的區域。角色部分。

dotnet 將基於 db 的 MVC 站點部署到 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;
}

您是否創建了一個繼承自IdentityUser的****ApplicationUser類?如果是這樣,您是否將ApplicationUser類所在的命名空間添加到Configuration類?

這是解決此錯誤的最合理的方法。

引用自:https://stackoverflow.com/questions/21502196