Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Custom nav toolbar using sitemap roles

Back to Forum: Tech Off
  • User profile image
    mrichman

    I have the following nav template:

    <asp:Repeater ID="TopNavRepeat" runat="server"
    DataSourceID="SiteMapDataSource1">
       <HeaderTemplate>
          <ul>
       </HeaderTemplate>
       <ItemTemplate>
          <li>
          <asp:HyperLink ID="HyperLink1" runat="server"
           Text='<%# Eval("Title") %>' NavigateUrl='<%# Eval("Url") %>'
           ToolTip='<%# Eval("Description") %>' />
          </li>
       </ItemTemplate>
       <FooterTemplate>
          </ul>
       </FooterTemplate>
    </asp:Repeater>

    How do I render the <li> for only those sitemap nodes for which the user's role has access? (i.e. roles="Admins" in Web.sitemap)

    Thanks,
    Mark

  • User profile image
    W3bbo

    mrichman wrote:
    How do I render the <li> for only those sitemap nodes for which the user's role has access? (i.e. roles="Admins" in Web.sitemap)


    Methinks like:


    <asp:Repeater ID="TopNavRepeat" runat="server"
    DataSourceID="SiteMapDataSource1">
       <HeaderTemplate>
          <ul>
       </HeaderTemplate>
       <ItemTemplate>
        <% if(User.Identity.IsInRole( "Admins" ) { %>
          <li>
          <asp:HyperLink ID="HyperLink1" runat="server"
           Text='<%# Eval("Title") %>' NavigateUrl='<%# Eval("Url") %>'
           ToolTip='<%# Eval("Description") %>' />
          </li>
        <% } %>
       </ItemTemplate>
       <FooterTemplate>
          </ul>
       </FooterTemplate>
    </asp:Repeater>

  • User profile image
    mrichman

    Right, but I have several roles and I want to drive it off the sitemap file like this:

    <siteMapNode url="~/UserProfile.aspx" title="Profile" description="" roles="*" />

    <siteMapNode url="~/Admin/Default.aspx" title="Admin" description="" roles="Admin" />

    <siteMapNode url="~/Seller/Storefronts/Default.aspx" title="Storefronts" description="" roles="Seller"/>

    Not sure how much conditional logic you can cram into a page without code-behind. I'm also not sure what I need to import to get "User.Identity.IsInRole" to resolve.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.