Site map different for each user using sitemap provider.

Last post 01-15-2007 4:27 AM by Dave Sussman. 7 replies.

Sort Posts:

  • Site map different for each user using sitemap provider.

    04-18-2006, 11:10 AM
    • Loading...
    • tiagonmas
    • Joined on 04-18-2006, 3:06 PM
    • Posts 9

    Hi There,

    I'm changing the SqlSiteMapProvider in order to fetch the site map from my existing tables. The problem is that the site map should be personalized for each user depending on database data and not on roles.

    How can I user SiteMapProvider on a user per user basis ?

     

    Thanks,

    Tiago Andrade e Silva

  • Re: Site map different for each user using sitemap provider.

    04-18-2006, 1:07 PM
    • Loading...
    • dannychen
    • Joined on 08-24-2004, 12:17 PM
    • Redmond, WA
    • Posts 839
    • AspNetTeam
      Moderator

    Tiago,
      While it's technically possible for the SiteMapProvider to not cache it's data and requery every time (to get per user data), it will have extremely poor performance and a very high query rate.

      The best technique for this kind of design is to cache the entire sitemap data (for ALL users) in memory and use logic in each of the query functions (CurrentNode, RootNode, ParentNode, ChildNodes, FindSiteMapNode, etc) that are able to filter the in-memory data per user as it is returned. 

      The alternative is to cache the per-user data as it is retreived so that you don't constantly requery the data but this has the potential to easily exceed the memory requirements of the first suggestion.

    --
    Danny

    disclaimer: Information provided is 'as is' and conveys no warranties or guarantees.
  • Re: Site map different for each user using sitemap provider.

    04-19-2006, 11:42 AM
    • Loading...
    • tiagonmas
    • Joined on 04-18-2006, 3:06 PM
    • Posts 9

    Thanks for your post Danny!

    After googling a bit more I did notice that the class is sealed and that the best thing is in fact the first approach you state: to cache the entire sitemap data for all users.

    The way to do this I think is overriding the IsAccessibleToUser method.

    "If you want to use your own authorization logic to check if a user has access to a node, you need to override the IsAccessibleToUser method. This method will be called from the StaticSiteMapProvider’s members that we have not overridden in this example, such as the FindSiteMapNode, GetParentNode and GetChildNodes methods etc."

    http://fredrik.nsquared2.com/viewpost.aspx?PostID=272&showfeedback=true

    Here is another link about Determining a SiteMapNode's visibility at runtime

     

     

     

  • Re: Site map different for each user using sitemap provider.

    04-19-2006, 3:39 PM
    • Loading...
    • dannychen
    • Joined on 08-24-2004, 12:17 PM
    • Redmond, WA
    • Posts 839
    • AspNetTeam
      Moderator

    Sure, that'll do the trick.... I tend to discourage most users from overriding IsAccessibleToUser because they usually do it without understanding the security implications... However, as long as you're aware of the effects and it does the job, go for it!  Read up more on it here: 

    http://blogs.msdn.com/dannychen/archive/2006/03/16/553005.aspx

    --
    Danny

    disclaimer: Information provided is 'as is' and conveys no warranties or guarantees.
  • Re: Site map different for each user using sitemap provider.

    08-24-2006, 1:02 PM
    • Loading...
    • CarlFisher
    • Joined on 04-28-2006, 4:02 PM
    • Posts 30

    dannychen:
     The alternative is to cache the per-user data as it is retreived so that you don't constantly requery the data but this has the potential to easily exceed the memory requirements of the first suggestion.

    Hi Danny,

    We have a situation where we're getting our sitemap data via a webservice that uses the user's login info, so we will need to cache the per-user data.  Fortunately our sitemap data is not very large.  My question is how to do this.  I've implemented a custom SiteMapProvider derived from StaticSiteMapProvider, but (obviously) it'll just cache whatever the first user gets. 

    How would I adapt my provider to cache per-user data and return it properly?

    Many thanks!

    Carl

  • Re: Site map different for each user using sitemap provider.

    01-13-2007, 12:28 PM
    • Loading...
    • vanecek
    • Joined on 12-14-2006, 6:18 PM
    • Posts 3
    CarlFisher:

    We have a situation where we're getting our sitemap data via a webservice that uses the user's login info, so we will need to cache the per-user data.  Fortunately our sitemap data is not very large.  My question is how to do this.  I've implemented a custom SiteMapProvider derived from StaticSiteMapProvider, but (obviously) it'll just cache whatever the first user gets. 

    How would I adapt my provider to cache per-user data and return it properly?

    I've read this article http://download.microsoft.com/download/2/a/e/2aeabd28-3171-4b95-9363-22150625a6a5/asp.net%20provider%20model.pdf . For my opinion, You must not derive from StaticSiteMapProvider but from SiteMapProvider class.

    Deriving from StaticSiteMapProvider is appropriate for custom providers that read node data once (or infrequently) and then cache the information for the lifetime of the provider. Deriving from SiteMapProvider is appropriate for custom providers that query a database or other underlying data source in every method call.

    But there are more methods to be implemented than by StaticSiteMapprovider.

  • Re: Site map different for each user using sitemap provider.

    01-14-2007, 9:34 AM
    • Loading...
    • CarlFisher
    • Joined on 04-28-2006, 4:02 PM
    • Posts 30

    Yes, sorry, I never wrote back here with my resolution.  I ended up changing my provider to be based on SiteMapProvider rather than StaticSiteMapProvider.  Dave Sussman was kind enough to supply me with some sample code of a per-user based SiteMapProvider he wrote some time ago that I was able to use to see what I needed to do.  Since my sitemap data is fairly small, I store it in each user's Session.  I can provide more detail if anyone wants when I am back at work tomorrow.

     Carl

  • Re: Site map different for each user using sitemap provider.

    01-15-2007, 4:27 AM

    And in case anyone wants it, that code is available at http://www.ipona.com/samples/ANV201%20-%20ASP.NET%202.0%20Navigation.zip. This code doesn't do any custom type of caching, nor does it allow for changes to the database menu to change the menu (ie a notification) - I've never had time to do that.

    Dave

Page 1 of 1 (8 items)