ASP.NET Menu Control (Security Trimming)

Here I am using the ASP.NET Menu control with Security Trimming enabled to show/hide nodes to users to certain roles.

There are 2 roles: administrator and projectdirectors.

The problem is that for the "Print Checks" node, it is appearing for users in the projectdirectors role when clearly it is assigned the administrator role.

It is weird because it works for the Reports node and will hide the "By Date" node to projectdirectors.

I don't know if this is relevant but the /Checks/ and /Reports/ urls are using ASP.NET routing.

I am using C# with .NET 3.5 SP1.

Any ideas?
Web.sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
  <siteMapNode url="~/Default.aspx" title="Home">
    <siteMapNode title="Reports" roles="*">
      <siteMapNode url="~/Reports/View/ByDate" title="By Date" roles="administrator" />
      <siteMapNode url="~/Reports/View/ByStudy" title="By Study" roles="projectdirectors" />
    </siteMapNode>
    <siteMapNode title="Checks" roles="*">
      <siteMapNode url="~/Checks/View" title="View Checks" roles="*" />
      <siteMapNode url="~/Checks/Print" title="Print Checks" roles="administrator" />
      <siteMapNode url="~/InvalidChecks.aspx" title="Invalid Checks" roles="administrator" />
    </siteMapNode>
    <siteMapNode title="User" roles="*">
      <siteMapNode url="~/User/Profile.aspx" title="Profile" />
      <siteMapNode url="~/User/ChangePassword.aspx" title="Change Password" />
    </siteMapNode>
    <siteMapNode title="Admin" roles="administrator">
      <siteMapNode url="~/Admin/AddUser.aspx" title="Add User" roles="administrator" />
      <siteMapNode url="~/Admin/ViewUsers.aspx" title="View Users" roles="administrator" />
    </siteMapNode>
  </siteMapNode>
</siteMap>

Open in new window

menu.jpg
LVL 8
RyanAndresAsked:
Who is Participating?
 
RyanAndresAuthor Commented:
I figured it out. You must set authorizations in web.config rather than the roles attributes in .sitemap

See

http://aspadvice.com/blogs/dsussman/archive/2004/10/16/2268.aspx
and
http://aspadvice.com/blogs/dsussman/archive/2005/03/02/2271.aspx
0
 
RyanAndresAuthor Commented:
This is how the Menu control is placed in my .master page.
        <asp:LoginView ID="NavigationLoginView" runat="server">
            <LoggedInTemplate>
                <div id="nav" style="background-color: #DDDDDD; width: 100%; float: left;">
                    <div style="float: left; display: block;">
                        <asp:Menu ID="MenuMain" runat="server" BackColor="#DDDDDD" DataSourceID="SiteMapDataSource1"
                            DynamicHorizontalOffset="2" StaticSubMenuIndent="10px" DynamicEnableDefaultPopOutImage="False"
                            StaticDisplayLevels="2" StaticEnableDefaultPopOutImage="False" Orientation="Horizontal">
                            <StaticSelectedStyle BackColor="#DDDDDD" />
                            <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                            <DynamicHoverStyle BackColor="#DDDDDD" ForeColor="White" />
                            <DynamicMenuStyle BackColor="#DDDDDD" />
                            <DynamicSelectedStyle BackColor="#DDDDDD" />
                            <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                            <StaticHoverStyle BackColor="#DDDDDD" ForeColor="White" />
                        </asp:Menu>
                    </div>
                    <div style="float: right; display: block; background-color: #DDDDDD; padding-top: 2px; padding-bottom: 2px;
                        padding-left: 5px;">
                        Logged in as:
                        <asp:LoginName ID="LoginName" runat="server" />
                        <asp:LoginStatus ID="LoginStatus" runat="server" OnLoggedOut="LoginStatus1_LoggedOut"
                            LogoutAction="RedirectToLoginPage" />
                        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
                    </div>
                </div>
            </LoggedInTemplate>
        </asp:LoginView>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.