Asked by:
Change View according to user privilege (Active Directory ASP.NET MVC C# project)

Question
-
Hello,
I am developing an intranet website using ASP.NET MVC and C# that fetches data from the company's Active Directory. I have just finished implementing authorization (login) according to this tutorial: http://tech.trailmax.info/2016/03/using-owin-and-active-directory-to-authenticate-users-in-asp-net-mvc-5-application/#disqus_thread.
I would like to know how someone would go about changing the View in an MVC project according to the user rights assigned to them. I have a partial view for my menu on the left of page and if the user has such or such rights, then he can see differents options in the menu. Here's my menu for now:
<div class="sidebar-nav"> <div class="navbar navbar-default" role="navigation"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-navbar-collapse"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <span class="visible-xs navbar-brand">Sidebar menu</span> </div> <div class="navbar-collapse collapse sidebar-navbar-collapse"> <ul class="nav navbar-nav" id="sidenav01"> <li class="active"> <a href="#" data-toggle="collapse" data-target="#toggleDoc" data-parent="#sidenav01" class="collapsed"> <span class="glyphicon glyphicon-folder-close"></span> Documentation <span class="caret pull-right"></span> </a> <div class="collapse" id="toggleDoc" style="height: 0px;"> <ul class="nav nav-list"> <li><a href="#">Documentation 1.1</a></li> <li><a href="#">Documentation 1.2</a></li> <li><a href="#">Documentation 1.3</a></li> </ul> </div> </li> <li class="active"> <a href="#" data-toggle="collapse" data-target="#toggleExploit" data-parent="#sidenav01" class="collapsed"> <span class="glyphicon glyphicon-folder-close"></span> Exploitation <span class="caret pull-right"></span> </a> <div class="collapse" id="toggleExploit" style="height: 0px;"> <ul class="nav nav-list"> <li><a href="#">Exploitation 2.1</a></li> <li><a href="#">Exploitation 2.2</a></li> <li><a href="#">Exploitation 2.3</a></li> </ul> </div> </li> <li><a href="#"><span class="glyphicon glyphicon-folder-close"></span> Infos Utiles</a></li> <li><a href="#"><span class="glyphicon glyphicon-folder-close"></span> Liens <span class="badge pull-right">42</span></a></li> <li class="active"> <a data-toggle="collapse" data-target="#toggleSearch" data-parent="#sidenav01" class="collapsed"> <span class="glyphicon glyphicon-cog"></span> Recherches <span class="caret pull-right"></span> </a> <div class="collapse" id="toggleSearch" style="height: 0px;"> <ul class="nav nav-list"> <li><a href="~/Search/SearchUser">Rechercher un utilisateur</a></li> <li><a href="~/Search/SearchComputer">Rechercher un ordinateur</a></li> <li><a href="#">Exploitation 2.3</a></li> </ul> </div> </li> </ul> </div><!--/.nav-collapse --> </div> </div>
Ok it's a bit big for an example, but let's say I would have <li> elements generate according to a user right. Or maybe the Exploitation point would be visible to only some users. Many rules to apply like this.
I was thinking of maybe making separate pages according to user rights, but what happens if I have users with unique rights? I cannot make a page for each user so maybe there is a more practical way of doing things out there?
Thanks for your help!
Thursday, June 1, 2017 12:26 PM
All replies
-
Please post questions related to MVC in the ASP.NET forums.Thursday, June 1, 2017 1:44 PM
-
Oups sorry, I'm new here.Thursday, June 1, 2017 2:01 PM