0
我目前將我的代碼從ASP NET MVC 4升級到5.我在添加OWIN安全性後出現問題,下面是我使用的代碼。授權錯誤,'RoleEntity不是當前上下文模型的一部分'
[Authorize(Roles="Admin")]
public async Task<string> test()
{
var role = "";
using (
var userManager =
new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
{
var rolesForUser = await userManager.GetRolesAsync(User.Identity.GetUserId());
return "test " + User.Identity.GetUserName() + " " + rolesForUser.ElementAt(0);
}
}
其送花兒給人給我的錯誤
的實體類型RoleEntity是不是該機型爲當前上下文的一部分。
當我使用[Authorize(Users="username")]
時,它正常工作,它只在將'Users'更改爲'Roles'時出錯。我的數據庫是SQLServer的使用實體框架5.