Is there a possibility to hand over the Result of the Authorize-Attribute to the View?
Let's assume I want to hide 5 links in my Index view based on the memberships of a User.
[Authorize(Roles = "Admin")]
public ActionResult Index(){
....
}
The code above will prevent all users that are not part of the Admin-Group from visiting the Index page.
@{
if(User.IsInRole("Admin"){
<a href="#">Some link to be hidden</a>
}
}
This code will hide the link if the User is not part of the Admin role. This is basically what I want BUT using this method I have to change the role name on every hidden link if the role would change.
Isn't there something like a combination of both? (Schema see below)
[Authorize(Roles = "Admin")] //This will pass true to the View if the User is a member of the group "Admin"
public ActionResult Index(){
....
}
@{
if(User.IsAuthenticated){ //This will read the "Token" and if it's true the if statement will get executed.
<a href="#">Some link to be hidden</a>
}
}
So - if the User is in Role "Admin" the link will be shown. Is this possible?