Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - How to efficiently create dynamic user-specific menu from database

this is my first time posting on StackOverflow but this site is awesome. Thanks in advance for any help you're able to give.

I have a site which gives users access to different pages based on their permissions so each user needs to have their menu dynamically generated when they log in. However, a user's options probably won't be changing very often.

The site currently has a Master page which pulls a list of their pages from the database and builds a menu. It does this each time the user loads a page.

I wanted to cut down on calls to the database so started putting the menu data into a Session variable. I was hoping someone more experienced could help me out in making sure that this is the best way to do it. I think I would prefer a way to store it on the user's machine and not the server.

I have this is my Master's Page Load:

User u = new User(Page.User.Identity.Name, Globals.getCnString());
        DataTable menu;
        if(Session["MENU"] == null)
        {
            Session["MENU"] = u.getMenu();
        }
        menu = (DataTable)Session["MENU"];

        foreach (DataRow r in menu.Rows)
        {
           //build menu code here.
        }

Thanks again!

like image 423
ShawOfMordor Avatar asked Nov 14 '22 07:11

ShawOfMordor


1 Answers

If user's options won't be changing very often, why don't you build the menu only when the change happened, save it in user's profile table (in html format), and pass it to a literal control in the Master page instead of the menu, in that way you'll not store it on the user's machine(which is not recommended for a website).

like image 77
Alaa Avatar answered Dec 08 '22 00:12

Alaa