My requirement is admin user can grant other users to access number of pages in the site.
Users and their assigned page stores in database like following format.
ID | User ID | ClaimType | Page |
---|---|---|---|
1 | 1 | Test | Test.cshtml |
I'm trying to achieve this using claim based authorization in asp.net core project.
but the problem is thier is more then 150 pages so need to create 150 seperate policies in "program.cs" file.
Is that any other better way to achieve this goal?
Only assigned users can access the respected action method in specific controller.
I was implemented claim based authorization for each pages.
Program.cs
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("TestPolicy", policy=> policy.RequireClaim("Test"));
options.AddPolicy("SamplePolicy", policy => policy.RequireClaim("Sample"));
/* For each pages defined separate policies in program.cs and more then 200 pages available in project */
});
Controller
[HttpGet]
[Authorize(Policy = "TestPolicy")]
public async Task<IActionResult> Test()
{
return View();
}