【发布时间】:2023-03-11 23:38:01
【问题描述】:
我正在尝试使用我的自定义经理进行基于角色的授权。我有用户表和角色表。模型看起来像这样
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);
}
}
我可以在User.Roles 列表中添加角色 ID。所以我创建了一个名为admin 的角色并将其添加到用户列表中。添加成功。
然后我在我的一个控制器上试试这个
[Authorize(Roles = "admin")]
但它不起作用。我错过了什么吗?
【问题讨论】: