0

I'm trying to control the menu options depending user roles and permission, after the user login. I saved the user in session and then I get the roles and permissions from data base, then I want to show the main page which is a Master with the menu options how can I do it without using javascript, I'm using c# asp.net.

Jesus Ramos
  • 22,940
  • 10
  • 58
  • 88

3 Answers3

1
if(Roles.IsUserInRole(roleName))
{
    // show controls accordingly
}
else
{
    // hide controls accordingly
}
JG in SD
  • 5,427
  • 3
  • 34
  • 46
0

Try this

if(User.IsInRole("Admin"))
{
   //show menu
}
else
{
   //hide menu
}
codingbiz
  • 26,179
  • 8
  • 59
  • 96
0

You could handle this with server tags on the .aspx side.

<% if (User.IsRole("Administrator")) { %>
    <div>Admin Stuff</div>
<% } %>

or you could handle it all server side and wrap the content in PlaceHolders and show/hide them accordingly

<asp:PlaceHolder id="AdminPlaceHolder" runat="server">
    <div>Admin Stuff</div>
</asp:PlaceHolder>

AdminPlaceHolder.Visible = User.IsRole("Administrator");
hunter
  • 62,308
  • 19
  • 113
  • 113