This question already has an answer here:
- Usage of User.IsInRole() in a View 2 answers
I have 3 roles on my page, so I want to get access to link with two roles.
I try something like this
@if(User.IsInRole("Admin,User"))
{
//my code
}
Or this
@if (User.IsInRole("Admin") && User.IsInRole("User"))
{
//my code
}
No one work's, the only one who I managed to works is this:
@if (User.IsInRole("Admin")
But this last one it's only for one Role, How can I do that I want?
This is reasonable, if you consider what the method
IsInRole
does.That being said a user may has the role of Admin (so
UserIsInRole("Admin")
returns true) but may not has the role of User (soUserIsInRole("User")
returns false). SoUser.IsInRole("Admin") && User.IsInRole("User")
would evaluate tofalse
.That you might need is this: