How to hide parts of a page based on user permissions using asp.net identity? [closed]

0

I have a project in mvc and I'm using asp.net identity, I have different types of profiles, example adm / tutor / master / user and I have access areas for each profile, besides the "home" view that has the urls that match each profile. I wanted a solution that using asp.net identity I can hide certain urls in the "home" view so that the other profiles do not see. This would be done with an implementation at the time the user logs in, hence it would hide urls that he would not have access to, that is, if a regular user logs in, only the user url will appear to him. I would like to know if asp.net identity has some implementation of its own for this type of control.

    
asked by anonymous 07.12.2016 / 18:09

1 answer

1

In your cshtml file you can make conditions to display the menus. I do not know anything ready for that. 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 Role

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