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!
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With