lundi 17 août 2015

applying security among menus

below is my model

public class security
{  
    public long id { get; set; }
    public long user_id { get; set; }
    public long submenu_id { get; set; }
    public bool flag { get; set; }

}

it the flag is true the user has access to submenu.

Currently what i am doing is . When the user logged in the details in this model will be pulled out and store in seperate session variable.

eg: - var c = db.security.where(m=> m.user_id == id).Orderby(id);

if(c.submenu_id == 1 && c.flag == true)
   session["mem_add"] = "true";
else
   session["mem_add"] = "false";

Then in the layout view will check this session variable and if true the menu will display, but problem is there are 16 sub menus and can increase it later.So I have to create seperate session variables for each submenu. Is there any better way to solve this problem?

Edited

@if(Session["mem_add"] == "true")
{
          <li class="active"><a href="@Url.Action("Index", "UpdateDetail")">
            <img src="@Url.Content("~/Images/Enrollments.png")" alt=""><span class="title"><b>
    @Resources.Resources.UpdateMyDetail</b> </span> </a></li>
}

Aucun commentaire:

Enregistrer un commentaire