I've successfully implemented role and claim (policy) based authorisation in my app. I'm using ASP.NET CORE 7 MVC. The top menu navigation is hidden base on the login user's role something like this:
@if (User.IsInRole("Admin"))
{
<li class="nav-item"><a class="nav-link text-dark" asp-action="" asp- controller="">Audit</a>
</li>
}
so the above will only show if the login user has a role of Admin (doesn't matter the policy assigned). My question is I want to show/hide the nav like based on the claim/policy assigned to other users (other than an Admin, say I want to select a specific user to access the audit page)
I thought I could do something like this (but it's not working)
@if(User.HasClaim(c => c.Type == "ViewAuditPage" && c.Value == "True"))
{
<li class="nav-item"><a class="nav-link text-dark" asp-action="" asp- controller="">Audit</a>
</li>
}
Any idea how to show/hide nav menu base on claim/policy Authorisation?