I want to know if it's possible to configure roles in te website menu to prevent to see some aspx, also if get the current role in the c# (code behind) once the user was loggedIn. Thank开发者_运维知识库s
If you are using asp.net roles provider and asp.net menu control, you can use the web.sitemap file to control the menu links display based on roles as below.
<siteMapNode url="/Test/Default.aspx" roles="Admin" title="Test" description="">
Otherwise you can use a loginview control to display different links based on roles as below.
<asp:LoginView runat="server">
<AnonymousTemplate>
Menu Link1
</AnonymousTemplate>
<RoleGroups>
<asp:RoleGroup Roles="Admin">
<ContentTemplate>
Menu Link2
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
If you are not using role providers and say store that information in the session or somewhere, you can use something similar in the aspx file.
<% if (Session["admin"].ToString() == "Admin") { %>
Link1
<% } else { %>
Link2
<%} %>
You can get the current roles for the logged in user as
string[] roleNames = Roles.GetRolesForUser();
精彩评论