0

My application has a number of different users, currently there are different masterpages set up for them. The idea is for some type of breadcrumb in the system i.e. home > details > ...

What is the best approach for this? I think I will need to define the separate paths that each user can have (all the pages they can view) in the Web.sitemap (will have multiple SiteMapPaths) and then add the sitemap control to masterpage and link them to the appropriate SiteMapPath, does this sound like the right way to approach this?

I am having an issue with setting up the SiteMapPath within the masterpage. I used the following tutorial http://geekswithblogs.net/azamsharp/archive/2006/08/16/88197.aspx to try to use the control, but the SiteMapPath control is not displaying on the masterpage when I log in do you know what the problem might be?

Web.sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

      <siteMapNode url="home.aspx" title=""  description="">
        <siteMapNode url="contacts.aspx" title=""  description="">   
    </siteMapNode>

</siteMap>

On the masterpage:

<asp:SiteMapPath ID="SiteMapPath1" runat="server">

          <RootNodeTemplate>

          <asp:HyperLink ID="HyperLink1" runat="server"
          Text='<%# Eval("title") %>' NavigateUrl='<%# Eval("url") %>' />

          </RootNodeTemplate>

          <NodeTemplate>
            <asp:HyperLink ID="HyperLink2" runat="server"
            Text='<%# Eval("title") %>' NavigateUrl='<%# Eval("url") %>' />
          </NodeTemplate>

          </asp:SiteMapPath>

Thank you

kt87
  • 51
  • 1
  • 3
  • 8

1 Answers1

0

If you are using FormsAuthentication to control authorization of users for the pages they can navigate then I would suggest including Roles as well. Then use securityTrimmingEnabled="ture" in sitemapprovider. That way you won't need separate sitemaps for each user.

Here is basics of how it works:

And you might want to share some code for us to know why what you tried is not working.

Edited:1

You don't need built-in Roles provider for this to work but you do need to add roles to the UserPrincipal. How to do that is shown here But you will need to write code that returns roles as string for each true value i.e. "admin" if admin is true for the user in database. Then add those roles to user Principal as shown in the link and it should work in combination with the first link.

Edit:2 You don't need that complex code for SiteMap to work. You simply drop it on your page and it will work based on your .sitemap file. Also you have title="" for the sitemapnode, set that to some value.

gbs
  • 7,196
  • 5
  • 43
  • 69
  • @kb88: Yes you add all pages as sitemapnodes in the web.sitemap. Then depending on your authorization settings in web.config, sitemapprovider+Asp.net will decide which page to show and which not. You then need not worry anything else. Do you have lot of restrictions or just few like you say only one user can view all pages what about rest? – gbs Mar 25 '11 at 21:43
  • there are five different users, two can view the same things and the other cannot do/view the same things as those users. Where do I the AuthenticateRequest event handler will this be needed on every masterpage? thank you – kt87 Mar 25 '11 at 21:52
  • @kb88: Ok then going with roles is good way. You add AuthenticateRequest in the Global.asax. – gbs Mar 25 '11 at 21:56
  • @kb88: I am not sure if that will be an easy route. But say if you go the User Principal route then you get that functionality of allowing users based on their role. Also you can use User.IsInRole method to do the check in case if you still want to do some customization. i.e. this can complement your existing class or you might even be able to get rid of your existing class that does that check in master page. – gbs Mar 25 '11 at 22:59