This is a migrated thread and some comments may be shown as answers.

Rendering menu items based on the logged-in user.

1 Answer 81 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 22 Sep 2008, 12:54 AM

Hi,

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?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 22 Sep 2008, 07:56 AM
Hello Brad,

You can use the security trimming feature of the SiteMapDataSource control. You can check those two links for more info:
http://msdn.microsoft.com/en-us/library/ms178429(VS.80).aspx
http://msdn.microsoft.com/en-us/library/ms178428.aspx

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
    { 
        PopulateMenuItems(thisUser.Role); 
        Session["Menu"] = RadMenu1.GetXml(); 
    } 
    else 
    { 
        RadMenu1.LoadXml(menuXml); 
    } 
 


All the best,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Menu
Asked by
Brad
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or