0

I am binding a web.sitemap to an asp:Menu, and want to assign classes to the menu items that require a login to access.

I know that in the siteMap section of the web.config file, if I set securityTrimmingEnabled="true" that it will only show items available to that user (roles/logged out/logged in). This is fine with me, but the users want to see these links.

So I am trying to make an indicator that these pages are locked, preferably adding a class to those links.

Thanks in advance!

tedski
  • 2,271
  • 3
  • 27
  • 48
  • Per [this meta discussion](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts), removing things like "Hi" and "Thanks" from posts is pretty standard procedure. I was not trying to deface your question in any way. – Josh Darnell Mar 14 '12 at 17:40
  • I understand, but I subscribe to RSolberg's answer. – tedski Mar 14 '12 at 18:31

1 Answers1

1

You may use a custom ITemplate for the DynamicItemTemplate property of the Menu. As alternative (I guess with less code but I never tried) you may attach to MenuItemDataBound event.

Adriano Repetti
  • 65,416
  • 20
  • 137
  • 208
  • Sounds good so far, but any idea on how I would catch whether a page requires the user be logged in? – tedski Mar 14 '12 at 14:45
  • Create your ITemplate (follow link for an example), attach in debug and watch what you get. The SiteMapNode has a method to check if it's accessible to current logged-in user or not. – Adriano Repetti Mar 14 '12 at 14:47
  • I can't seem to figure out how to do this, I've tried the MenuItemDataBound method and the DataItems don't really have a property for if they are accessible or not. As far as the ITemplate, I can't figure out how to create a custom one or get this method from the SiteMapNode. – tedski Mar 14 '12 at 15:41
  • Example at http://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.instantiatein.aspx – Adriano Repetti Mar 14 '12 at 15:44
  • Yeah, I saw that. Still don't understand. I ended up using the MenuItemDataBound event along with this custom class that mocks an HttpRequest: http://stackoverflow.com/questions/3390719/determine-if-current-page-requires-authorization it's a bit messy but it works – tedski Mar 14 '12 at 16:42