0

I want implement my own roles handling in controllers in .NET Core WEB API application. How to do this for the controller would want to support my own roles like in Identity. I don't know how to implement this to use my roles like this in original Identity.

I have 3 tables for the AppUsers:

  public class AppUser
  {
    public int Id { get; set; }
    public string Username { get; set; }
    public byte[] PasswordHash { get; set; }
    public byte[] PasswordSalt { get; set; }
    public virtual AppUserAddress Address { get; set; }
    public virtual AppUserRole Role { get; set; }
  }

  public class AppUserRole
  {
    public int Id { get; set; }
    public string Name { get; set; }
  }

And I want to use this roles Like this:

[HttpGet]
[Authorize(Roles = "Admin")]
   public ActionResult<IEnumerable<string>> Get()
   {
       return new string[] { "value1", "value2" };
   }
voltdev
  • 260
  • 1
  • 4
  • 9
  • Take a look at this question: https://stackoverflow.com/questions/51873269/asp-net-core-2-1-custom-roleprovider-with-windows-authentication/51873734#51873734 – ste-fu Jan 18 '19 at 15:56
  • This may be a path ... https://learn.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-2.2. No Identity modules needed, just some custom code to handle your requirements. – Scott Hoffman Jan 18 '19 at 21:17

0 Answers0