Hi All,,

Iam facing following problem in my application

I have two database tables

1) Groups table - is used to store the details of selected .aspx pages.

2) User table - is used to store details of users and associated group.This table even store the privileages associated with each user.

In my application iam using menu to navigate pages.

Whenever a user access my application only menus (i mean submenu or whatever ) associated with the login user should be displayed.

How I can do this?

Can anyone here please help me?

Thanks in advance

Nick

Is it same as you want ?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then createMenu() 
    End Sub

    Sub createMenu()
        Dim SQL As String
        Mn.Items.Clear()        

        Dim CnMenu As New SqlClient.SqlConnection
        Dim CnSubMenu As New SqlClient.SqlConnection
        Dim CnFunction As New SqlClient.SqlConnection

        SQL = "SELECT MasterMainMenu.MainMenuID, MasterMainMenu.MainMenuName, MainMenuLink FROM MasterMainMenu ORDER BY Seq"
        GetCN(CnMenu)
        Dim CmMenu As New SqlClient.SqlCommand(Sql, CnMenu)
        Dim RdMenu As SqlClient.SqlDataReader
        RdMenu = CmMenu.ExecuteReader()
        Do While RdMenu.Read
            Dim MenuItem As New MenuItem
            MenuItem = CreateMenuItem(SetStringValue(RdMenu.Item("MainMenuName")), SetStringValue(RdMenu.Item("MainMenuLink")), "")
            Mn.Items.Add(MenuItem)

            SQL = "SELECT SubMainMenuID, SubMainMenuName, Link, Target FROM MasterSubMainMenu WHERE MainMenuID='" & RdMenu.Item("MainMenuID").ToString.Trim & "' AND Disabled = 'N' ORDER BY SEQ"
            GetCN(CnSubMenu)
            Dim CmSubMenu As New SqlCommand(SQL, CnSubMenu)
            Dim RdSubMenu As SqlClient.SqlDataReader
            RdSubMenu = CmSubMenu.ExecuteReader
            Do While RdSubMenu.Read
                If SetStringValue(RdSubMenu.Item("Link")) <> "" Then
                    If Security.IsUserAllowed(Session("UserId"), SetStringValue(RdSubMenu.Item("SubMainMenuID")), UserAccess.CanDisplay) = True Then
                        Dim SubMenuItem As New MenuItem
                        SubMenuItem = CreateMenuItem(SetStringValue(RdSubMenu.Item("SubMainMenuName")), SetStringValue(RdSubMenu.Item("Link")), "")
                        MenuItem.ChildItems.Add(SubMenuItem)
                    End If
                Else
                    Dim SubMenuItem As New MenuItem
                    SubMenuItem = CreateMenuItem(SetStringValue(RdSubMenu.Item("SubMainMenuName")), SetStringValue(RdSubMenu.Item("Link")), "")
                    MenuItem.ChildItems.Add(SubMenuItem)

                    SQL = "SELECT MasterFunction.FunctionID, MasterFunction.FunctionName, FunctionLink FROM MasterUserFunctionDetail INNER JOIN MasterFunction ON MasterFunction.FunctionID=MasterUserFunctionDetail.FunctionID WHERE MasterUserFunctionDetail.UserID='" & Trim(Session("UserID")) & "' and MasterFunction.MainMenuID='" & SetStringValue(RdSubMenu.Item("SubMainMenuID")) & "' and ISNULL(DISABLED,'') = 'N' ORDER BY MasterFunction.SEQ "
                    GetCN(CnFunction)
                    Dim CmFunction As New SqlCommand(SQL, CnFunction)
                    Dim RdFunction As SqlClient.SqlDataReader
                    RdFunction = CmFunction.ExecuteReader
                    Do While RdFunction.Read
                        If Security.IsUserAllowed(Session("UserId"), RdFunction.Item("FunctionId").ToString.Trim, UserAccess.CanDisplay) = True Then
                            Dim FunctionMenuItem As New MenuItem
                            FunctionMenuItem = CreateMenuItem(SetStringValue(RdFunction.Item("FunctionName")), SetStringValue(RdFunction.Item("FunctionLink")), "")
                            SubMenuItem.ChildItems.Add(FunctionMenuItem)
                        End If
                    Loop
                    SetToNothing(CnFunction, RdFunction, CmFunction)
                End If
            Loop
            SetToNothing(CnSubMenu, RdSubMenu, CmSubMenu)
        Loop
        SetToNothing(CnMenu, RdMenu, CmMenu)
    End Sub

    Function CreateMenuItem(ByVal text As String, ByVal url As String, ByVal toolTip As String) As MenuItem
        Dim menuItem As New MenuItem()
        menuItem.Text = text
        menuItem.NavigateUrl = url
        menuItem.ToolTip = toolTip
        Return menuItem
    End Function
This article has been dead for over six months. Start a new discussion instead.