How to hide parts of a page based on user permissions using Asp.net Identity?

Asked

Viewed 58 times

0

I have a project in mvc and I am using the Asp.net Identity, I have different types of profiles, example Adm / tutoring / master / user and I have access areas for each profile, in addition to the view "home" that has the urls that correspond to each profile. I wanted a solution that using Asp.net Identity I can hide certain urls in the "home" view so that other profiles do not see. This would be done with an implementation at the time the user logs in, hence it would hide the url’s that he would not have access to, that is if an ordinary user logs in, only the user url will appear to him. I wonder if Asp.net Identity has some implementation for this type of control.

1 answer

1


In your cshtml file you can make conditions to display the menus. I don’t know anything ready for this. I use the solution below:

To display links to logged in users (any level):

 @if (User.Identity.IsAuthenticated)
 {
     <a href="#"> Minha Conta </a>
 }

To display links according to the User’s Role

  @if (User.IsInRole("Admin"))
  {
     <a href="#"> Criar novo usuário</a>
  }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.