Horizontal Menu Disappears with securityTrimmingEnabled="true"

I'm implementing ASP.NET roles in a site and using the securityTrimmingEnabled feature so people don't see menu items for pages they're not authorized to visit.

Once I got the roles and restrictions enabled, the entire menu disappeared as if the role had no authorization to see any items. That's security trimming gone wild!

It turns out that this is an issue when you're using a horizontal ASP.NET menu. You usually hide the root node of the sitemap file when using a horizontal menu because a top row with one lonely root item doesn't make sense. (The SiteMapDataSource ShowStartingNode property is set to False.)

The fix was to make sure that every role had access to the (unused) dummy siteMapNode at the root by including roles="*"  in web.sitemap shown below:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap  enableLocalization="true"
     xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="" title="" roles="*"  description="">
      <siteMapNode url="~/default.aspx" resourceKey="siteMapHome" 
       title="Home" roles="admin,account" description="" />
<!-----More nodes-->

Sheesh! Why do I lose time on these silly things? Is nothing ever easy?

 

Published Tuesday, February 12, 2008 3:00 PM by Ken Cox [MVP]
Filed under: , , ,

Comments

# Horizontal Menu Disappears with securityTrimmingEnabled=&quot;true&quot; - WebLog of Ken Cox

Pingback from  Horizontal Menu Disappears with securityTrimmingEnabled=&quot;true&quot; - WebLog of Ken Cox

# Horizontal Menu Disappears with securityTrimmingEnabled=&#8221;true&#8221; | videositemap.com

Pingback from  Horizontal Menu Disappears with securityTrimmingEnabled=&#8221;true&#8221; | videositemap.com

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Tuesday, February 12, 2008 8:44 PM by rajbk

More info here:

blogs.msdn.com/.../553005.aspx

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Friday, March 28, 2008 6:41 AM by drag

you are a genius my friend!!!!

thanks for sharing your experience!

i spent hours trying to solve exactly the same  problems!

keep up the good work!

ta

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Sunday, March 30, 2008 9:33 AM by SP

Thanks dude.

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Tuesday, May 06, 2008 5:44 PM by prisLena

What a magic.  You made my day and saved me from frustrations.  Thank you

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Tuesday, November 04, 2008 3:33 AM by WotlkPowerLeveling.com

Yes, its works for me too, thanks

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Thursday, November 13, 2008 11:03 AM by kj

Thanks!  I had been trying to figure this one out all morning.

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Tuesday, December 16, 2008 9:01 PM by a friend

I was reading MSDN and the correct form to resolve this issue is to write roles="*"

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Wednesday, February 25, 2009 9:32 AM by Salomon

Thanks ALOT ! Thanks for sharing !!!

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Wednesday, April 01, 2009 1:27 AM by Som Nath Shukla

thanks alot for sharing.

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Monday, December 14, 2009 10:46 AM by cdonner

I wish I had found your post before putting up a bounty on Stackoverflow (stackoverflow.com/.../1898674), but nevertheless, I am very happy that someone finally pointed me to it. What a waste of time this was ...

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Saturday, September 04, 2010 7:50 AM by Yogesh Patel

Thanks a lot.

I spent a lot of time for this solution. And now I got it. Thanks again for sharing ur knowledge.

# re: Horizontal Menu Disappears with securityTrimmingEnabled="true"

Wednesday, September 08, 2010 1:58 AM by Bharat

Thank you, this has saved my few hours.

Bharat

Leave a Comment

(required) 
(required) 
(optional)
(required)