Asp.Net MVC#[授权(角色)]
我正在尝试与我的定制经理进行基于角色的授权。我有用户表和角色表。模型看起来像这样Asp.Net MVC#[授权(角色)],c#,asp.net,azure,C#,Asp.net,Azure,我正在尝试与我的定制经理进行基于角色的授权。我有用户表和角色表。模型看起来像这样 public class Account : EntityModel { public string Username { get; set; } public string PasswordHash { get; set; } public string Email { get; set; } public Account() : base("1", Suid
public class Account : EntityModel
{
public string Username { get; set; }
public string PasswordHash { get; set; }
public string Email { get; set; }
public Account()
: base("1", Suid.NewSuid())
{
Roles = new List<String>();
}
public static IEnumerable<Account> GetAll()
{
return TableHelper.GetAll<Account>();
}
public List<String> Roles { get; set; }
public Account Save()
{
TableHelper.Save<Account>(this);
return this;
}
}
public class Role : EntityModel
{
public string Name { get; set; }
public String Id
{
get
{
return this.RowKey;
}
set
{
this.RowKey = value;
}
}
public Role()
: base("1", Suid.NewSuid())
{
}
public static IEnumerable<Role> GetAll()
{
return TableHelper.GetAll<Role>();
}
public static Role Get(string x)
{
return TableHelper.Get<Role>("1", x);
}
}
但它不起作用。我遗漏了什么吗?您是否添加了roleprovider以及它工作所需的其他功能
有一个类似的问题,它有一个很好的入门方法:…为什么?ASP.NET Identity是否自带内置角色提供程序?什么时候脱光的?我想知道,因为只有在我最新的项目中,
Authorize(Roles=“role”)
才停止运行——在以前的所有项目中,它都能完美地运行,而无需创建或添加roleprovider。ASP.NET4.5.2,MVC5。它确实是现成的,但我想知道他的dbcontext设置是否正确。
[Authorize(Roles = "admin")]