Last post Aug 11, 2015 07:29 AM by PatriceSc
Aug 11, 2015 06:44 AM|Hisanth|LINK
I am creating menu hide / show using role based
In my .aspx
<% if (Context.User.IsInRole("Admin"))
<li><a id="admin" href="../../Admin/AdminLanding.aspx"><i class="fa fa-user-plus"></i> Admin</a>
<li><a href="../../Admin/Register.aspx">New AppUser </a></li>
<li><a id="A3" href="#" runat="server">Role </a></li>
<% } %>
In my Global.asax.cs
string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
string UserRole = Master_Role.GetRoleById(int.Parse(roles)).RoleName;
//Let us set the Pricipal with our user specific details
e.User = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(username, "Forms"), UserRole.Split(';'));
How to get role?
Aug 11, 2015 07:29 AM|PatriceSc|LINK
Unclear. Some more context could help. Do you mean Context.User.IsInRole("Admin")) return a string rather than a boolean ??!!
Or do you have a problem with your later code? It seems rather you are retrieving anyway a single role from a variable we don't know about so more likely you assign anyway a single role to your user.
Also why do create your own principal? Where are your roles stored? Can't you just use an existing role provider?