I am trying to make role based authorization with my custom manager. I have User Table and Roles Table. The models looks like this
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;
}
}
Roles Model looks like 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);
}
}
I am able to add Role Id in User.Roles
list. So I create a role named admin
and add it to the users list. It is added successfully.
Then I try this on one of my controllers
[Authorize(Roles = "admin")]
but it doesn't work. Am I missing something?