I have a site with links throughout it for performing actions. Some need to be hidden if the user is not in the admin role. I am doing checking on the backend just in case someone types i n the url directly etc. but is it enough to have this in the razor view?
<ul>
<li>Home</li>
<li>Items</li>
@if(User.IsInRole("Admin"){
<li>Users</li>
}
</ul>
Yep, that is sufficient.
Or as I found in another post which i used lately:
so you can use this:
However, if you are using links to other pages which you need to prevent from accessing when not in a specific role. You should also include the Authorize attribute in the controllers you want to prevent them from accessing: