Binding menu items to a sitemap.
Posted
by Ricardo Deano
on Stack Overflow
See other posts from Stack Overflow
or by Ricardo Deano
Published on 2010-05-25T11:55:04Z
Indexed on
2010/05/25
12:11 UTC
Read the original article
Hit count: 523
Hello all..this is driving me nuts.
I have a navigation menu I would like to display based upon user roles (using.net membership) After several hours and headaches (from banging my head against the desk) I was wondering if someone can point me in the error of my ways.
Page:
<body>
<form runat="server">
<div class="page">
<div class="header">
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
<a href="~/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a>
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/Open/Close.aspx"/> ]
</LoggedInTemplate>
</asp:LoginView>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu"
IncludeStyleBlock="False" Orientation="Horizontal"
DataSourceID="AugustSiteMap" />
<asp:SiteMapDataSource ID="AugustSiteMap" runat="server" ShowStartingNode="false"/>
</div>
</div>
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" description="Home">
<siteMapNode title="Open Pages" description="Open Pages">
<siteMapNode url="~/Open/Login.aspx" title="Login Page" description="Login Page" roles="*"/>
<siteMapNode url="~/Open/Close.aspx" title="Thank you for using Valpak Data Solutions Online Reporting" description="Thank you for using Valpak Data Solutions Online Reporting" roles="*"/>
</siteMapNode>
<siteMapNode title="Logged In Open Pages" description="Logged In Open Pages">
<siteMapNode url="~/Landing.aspx" title="Landing Page" description="Landing Page" roles="*"/>
<siteMapNode url="~/ContactUs.aspx" title="Contact Us" description="Contact Us" roles="*"/>
</siteMapNode>
<siteMapNode title="Restricted Pages" description="Resticted Pages">
<siteMapNode url="~/Restricted/ProductSearch.aspx" title=" Product Search" description=" Product Search" roles="*"/>
<siteMapNode url="~/Restricted/ReportOutput.aspx" title="Report Output" description="Report Output" roles="Admin"/>
</siteMapNode>
</siteMapNode>
</siteMap>
Webconfig:
<roleManager enabled="true" />
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers>
<add name="XmlSiteMapProvider"
description="AugustSiteMap"
type="System.Web.XmlSiteMapProvider "
siteMapFile="AugustSiteMap.sitemap"
securityTrimmingEnabled="true" />
</providers>
</siteMap>
How can I ensure that when the user is logged in, the appropriate menu items are displayed on the Landing page?
Please excuse my ignorance. Still new to all of this and my current method of 'trial and error' has seen me reach suicide levels this morning!
© Stack Overflow or respective owner