Rendering menu items based on the logged-in user.

2 posts, 0 answers
  1. Brad
    Brad avatar
    11 posts
    Member since:
    Mar 2008

    Posted 21 Sep 2008 Link to this post


    I need a scenario where the menu structure inculding each of the individual menu items are loaded depending on the user's login.
    This information comes from a database. Im using the telerik RadMenu. Now the only way i can see how to do this is 'loading' the items depending on the user (or user's role) on each page load:

        protected void Page_Load(object sender, EventArgs e)

            PopulateMenuItems( thisUser.Role );

    But this seems very inefficient. By 'inefficient' i mean rendering the menu on a per-page basis. I know about the databinding, but doesn't this mean ill have to define the menu structure for EVERY user (or user role) in the system (which is way too many). Is there some other way?

    Doing it on a per-page basis seems long-winded. Is there a way to do it on a per-login basis (i.e. only 'once' when the user logs in?). Isnt there a way to say define the menu structure 'once' when the user logins in, thus the menu items can simply be displayed?


  2. Atanas Korchev
    Atanas Korchev avatar
    8462 posts

    Posted 22 Sep 2008 Link to this post

    Hello Brad,

    You can use the security trimming feature of the SiteMapDataSource control. You can check those two links for more info:

    The other possible solution would be to populate the menu only once and store its state in the session. You can use the GetXml method to retrieve the menu items in XML format then LoadXml to load it back if the menu items are already in the session. Here is a code snippet:

    protected void Page_Load(object sender, EventArgs e) 
        string menuXml = (string)Session["Menu"]; 
        if (menuXml == null
            Session["Menu"] = RadMenu1.GetXml(); 

    All the best,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top