locked
CSS Menu and Security RRS feed

  • Question

  • User804724058 posted

    Hi guy's

    i'm using CSS Menu on my master page, i have question because this is my first menu from CSS. Can I hide some levels in menu based on security role in web application. 

    So if user log on site with role= "RN" he need to see just menu "RN", if he is in role = "VIP" he need to see "VIP" and "RN" in menu.

    Does anybody have some idea for me, sorry i'm rookie :)

    Example:

            <ul id="nav">

            
            <li><a href="Login.aspx" visible="false"><span>Home</span></a></li>
    <li><a href="#nogo2" id="RN"  visible="false"><span>Radni nalozi</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="#nogo19">Unos radnih sati</a></li>
    <li><a href="#nogo20">Pregled radnih sati</a></li>
    <li><a href="#nogo21">Prekovremeni</a></li>
    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
    </li>
    <li><a href="#nogo22" id="VP"><span>Voditeljski dio</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="#nogo23">Unos planiranih radnih sati</a></li>
    <li><a href="#nogo24">Odobrenje prekovremenih</a></li>
    <li><a href="#nogo25">Odobrenje fakturiranih</a></li>
    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
    </li>
    <li><a href="#nogo27" id="ADMIN"><span>Administracija</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="Uloga.aspx">Uloga</a></li>
    <li><a href="#nogo50">Projekata</a></li>
    <li><a href="Akcija.aspx">Akcija</a></li>
    <li><a href="#nogo52">Djelatnika</a></li>
    <li><a href="#nogo52">WEB Rola</a></li>
    <li><a href="#nogo52">Tvrtki</a></li>
    <li><a href="Drzava.aspx">Dr&#382;ava</a></li>
    <li><a href="#nogo52">Broj Radnih sati po podru&#382;nici</a></li>
    <li><a href="#nogo52">Kalendar po podru&#382;nici</a></li>
    <li><a href="#nogo52">A&#382;uriranje GO/BO</a></li>
    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
    </li>
            
    </ul>  <ul id="nav">

            

            <li class="top"><a href="Login.aspx" class="top_link" ><span>Home</span></a></li>

    <li class="top"><a href="#nogo2" id="RN" class="top_link"><span class="down">Radni nalozi</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub">

    <li><a href="#nogo19"> Test 1</a></li>

    <li><a href="#nogo20"> Test 2 </a></li>

    <li><a href="#nogo21"> Test 2 </a></li>

    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

    </li>

    <li class="top"><a href="#nogo22" id="VP" class="top_link"><span class="down">Voditeljski dio</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub">

    <li><a href="#nogo23">Test 1</a></li>

    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

    </li>

    <li class="top"><a href="#nogo27" id="ADMIN" class="top_link"><span class="down">Administracija</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub">

    <li><a href="Uloga.aspx">Test 2</a></li>

    <li><a href="#nogo50"> Test 3</a></li>

    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

    </li>

            

    </ul>  

    Wednesday, October 14, 2009 8:19 AM

Answers

  • User804724058 posted

    This is my CSS menu in master page:

    <div id="navtop" runat = "server">
            <ul id="nav" runat = "server" class= "nav">
            
            <li runat = "server" id="nav_home"><a href="Login.aspx" ><span>Home</span></a></li>
            
            <li id="nav_RN" runat = "server"  ><a href="#nogo2" id="RN"><span>Radni nalozi</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="rn.aspx">Unos radnih sati</a></li>
    <li><a href="#nogo19">Izmjena radnih sati</a></li>
    <li><a href="#nogo19">Zaključavanje perioda</a></li>
    <li><a href="#nogo20">Pregled radnih sati</a></li>
    <li><a href="#nogo21">Prekovremeni</a></li>
       </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
       </li>
    <li id="nav_vp" runat = "server"><a href="#nogo22"><span>Voditeljski dio</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="#nogo23">Unos planiranih radnih sati</a></li>
    <li><a href="#nogo24">Odobrenje prekovremenih</a></li>
    <li><a href="#nogo25">Odobrenje fakturiranih</a></li>
       </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
       </li>

    <div id="navtop" runat = "server">

            <ul id="nav" runat = "server" class= "nav">

            

            <li runat = "server" id="nav_home" class="top"><a href="Login.aspx" class="top_link" ><span>Home</span></a></li>

            

            <li id="nav_RN" runat = "server" class="top"  ><a href="#nogo2" id="RN" class="top_link"><span class="down">Radni nalozi</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub">

    <li><a href="rn.aspx">Child1</a></li>

    <li><a href="#nogo19"> Child2</a></li>

    <li><a href="#nogo19"> Child3</a></li>

    <li><a href="#nogo20"> Child4</a></li>

    <li><a href="#nogo21"> Child5</a></li>

       </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

       </li>

    <li id="nav_vp" runat = "server" class="top"><a href="#nogo22" class="top_link"><span class="down">Parent 1</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub">

    <li><a href="#nogo23"> Child1</a></li>

    <li><a href="#nogo24"> Child2</a></li>

    <li><a href="#nogo25"> Child3</a></li>

       </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

       </li> and so on....


    And when i loading the page i put this code:


        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            If User.IsInRole(ConfigurationManager.AppSettings("User").ToString) Then

                Me.Master.FindControl("nav_home").Visible = True

                Me.Master.FindControl("nav_RN").Visible = True

                Me.Master.FindControl("nav_vp").Visible = False

                Me.Master.FindControl("nav_admin").Visible = False

                Exit Sub

            ElseIf User.IsInRole(ConfigurationManager.AppSettings("PowerUser").ToString) Then

                Me.Master.FindControl("nav_home").Visible = True

                Me.Master.FindControl("nav_RN").Visible = True

                Me.Master.FindControl("nav_vp").Visible = True

                Me.Master.FindControl("nav_admin").Visible = False

                Exit Sub

            ElseIf User.IsInRole(ConfigurationManager.AppSettings("Administrator").ToString) Then

                Me.Master.FindControl("nav_home").Visible = True

                Me.Master.FindControl("nav_RN").Visible = True

                Me.Master.FindControl("nav_vp").Visible = True

                Me.Master.FindControl("nav_admin").Visible = True

                Exit Sub

            End If

            Response.Redirect("../no_access.aspx")

        End Sub


    This code is just for show or hide menu in css, you can also put this code for checking permissions to access


            If User.IsInRole(ConfigurationManager.AppSettings("Administrator").ToString) Or _

            User.IsInRole(ConfigurationManager.AppSettings("PowerUser").ToString) Then

    /* put something or control css menu */

                Exit Sub

            End If

            Response.Redirect("../no_access.aspx")

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 22, 2009 5:09 AM

All replies

  • User980627933 posted

    I think easiest in your defined structure is:

    <ul id="nav">

            
            <li><a href="Login.aspx" visible="false"><span>Home</span></a></li>
    <li><a href="#nogo2" id="RN"  visible="false"><span>Radni nalozi</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="#nogo19">Unos radnih sati</a></li>
    <li><a href="#nogo20">Pregled radnih sati</a></li>
    <li><a href="#nogo21">Prekovremeni</a></li>
    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
    </li>
    <li><a href="#nogo22" id="VP"><span>Voditeljski dio</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="#nogo23">Unos planiranih radnih sati</a></li>
    <li><a href="#nogo24">Odobrenje prekovremenih</a></li>
    <li><a href="#nogo25">Odobrenje fakturiranih</a></li>
    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
    </li>
    <li><a href="#nogo27" id="ADMIN"><span>Administracija</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="Uloga.aspx">Uloga</a></li>
    <li><a href="#nogo50">Projekata</a></li>
    <li><a href="Akcija.aspx">Akcija</a></li>
    <li><a href="#nogo52">Djelatnika</a></li>
    <li><a href="#nogo52">WEB Rola</a></li>
    <li><a href="#nogo52">Tvrtki</a></li>
    <li><a href="Drzava.aspx">Dr&#382;ava</a></li>
    <li><a href="#nogo52">Broj Radnih sati po podru&#382;nici</a></li>
    <li><a href="#nogo52">Kalendar po podru&#382;nici</a></li>
    <li><a href="#nogo52">A&#382;uriranje GO/BO</a></li>
    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
    </li>
            
    </ul>  <ul id="nav">

     

            <li><a href="Login.aspx" ><span>Home</span></a></li>

    <li class="top" id="liRN" style="display:none;"><a href="#nogo2" id="RN"><span class="down">Radni nalozi</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>

    <li><a href="#nogo19"> Test 1</a></li>

    <li><a href="#nogo20"> Test 2 </a></li>

    <li><a href="#nogo21"> Test 2 </a></li>

    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

    </li>

    <li class="top" id="liVP" style="display:none;"><a href="#nogo22" id="VP" class="top_link"><span>Voditeljski dio</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>

    <li><a href="#nogo23">Test 1</a></li>

    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

    </li>

    <li class="top" id="liAdmin" style="display:none;"><a href="#nogo27" id="ADMIN" class="top_link"><span class="down">Administracija</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>

    <li><a href="Uloga.aspx">Test 2</a></li>

    <li><a href="#nogo50"> Test 3</a></li>

    </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

    </li>

     

    </ul>

    Register a script from server to show li based on role like:

    document.getElementById('liRN').style.display = '';

    Wednesday, October 14, 2009 11:29 AM
  • User804724058 posted

    Thanks Mohsin, i defined structure with ID, i was having idea when calling some page to change that display, so my idea was to put code like this in aspx.VB file


        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If User.IsInRole(ConfigurationManager.AppSettings("Konz").ToString) Or _
            User.IsInRole(ConfigurationManager.AppSettings("GKonz").ToString) Then
                MasterPage.getElementById('liRN').style.display = '';
                Exit Sub
            End If
            Response.Redirect("../nemate_pravo_pristupa.aspx")
        End Sub

         Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If User.IsInRole(ConfigurationManager.AppSettings("Konz").ToString) Or _
            User.IsInRole(ConfigurationManager.AppSettings("GKonz").ToString) Then
                /change display on some id/
                Exit Sub
            End If
            Response.Redirect("../something.aspx")
        End Sub


    What code i can put here, please the easiest way for rookie like me :)


    Thanks one more time,

    House  

    Wednesday, October 14, 2009 2:49 PM
  • User980627933 posted

    Yes that what I told you in my previous reply. Use addition IDs in your html structure and on server use this code:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If User.IsInRole(ConfigurationManager.AppSettings("Konz").ToString) Or _
            User.IsInRole(ConfigurationManager.AppSettings("GKonz").ToString) Then
                Page.RegisterStartupScript("roleImp", "document.getElementById('liRN').style.display = '';") //liRN based on the role.
                Exit Sub
            End If
            Response.Redirect("../something.aspx")
        End Sub
    Wednesday, October 14, 2009 4:20 PM
  • User804724058 posted

    Hi,

    when i put this code i get the following error

    'Public Overridable Sub RegisterStartupScript(key As String, script As String)' is obsolete: 'The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script) 

    Do you know maybe what is the problem ?

    BR,

    House 

    Thursday, October 15, 2009 4:36 AM
  • User980627933 posted

    Actually in the newer version of .NET Framework ClientScript.RegisterStartupScript(Type type, string key, string script) is the new method. Actually messaging showing instead of using old method, use new one. You can use it like this:

    ClientScript.RegisterStartupScript(this, "key", "script")

    Thursday, October 15, 2009 9:16 AM
  • User804724058 posted

    Hi, I resolve the problem thx, i was not using 

    ClientScript.RegisterStartupScript(this, "key", "script")

    but you give me good direction to resolve the problem

    i was using 

    User.IsInRole(ConfigurationManager.AppSettings("Administrator")

    If you want i can put here my solution and mark yours as answer.


    Thx,

    House

    Thursday, October 15, 2009 3:23 PM
  • User980627933 posted

    I think its better to put your solution here. It'll be good for future users.

    Thursday, October 15, 2009 3:41 PM
  • User804724058 posted

    This is my CSS menu in master page:

    <div id="navtop" runat = "server">
            <ul id="nav" runat = "server" class= "nav">
            
            <li runat = "server" id="nav_home"><a href="Login.aspx" ><span>Home</span></a></li>
            
            <li id="nav_RN" runat = "server"  ><a href="#nogo2" id="RN"><span>Radni nalozi</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="rn.aspx">Unos radnih sati</a></li>
    <li><a href="#nogo19">Izmjena radnih sati</a></li>
    <li><a href="#nogo19">Zaključavanje perioda</a></li>
    <li><a href="#nogo20">Pregled radnih sati</a></li>
    <li><a href="#nogo21">Prekovremeni</a></li>
       </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
       </li>
    <li id="nav_vp" runat = "server"><a href="#nogo22"><span>Voditeljski dio</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
    <!--[if lte IE 6]><table><tr><td><![endif]--><ul>
    <li><a href="#nogo23">Unos planiranih radnih sati</a></li>
    <li><a href="#nogo24">Odobrenje prekovremenih</a></li>
    <li><a href="#nogo25">Odobrenje fakturiranih</a></li>
       </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
       </li>

    <div id="navtop" runat = "server">

            <ul id="nav" runat = "server" class= "nav">

            

            <li runat = "server" id="nav_home" class="top"><a href="Login.aspx" class="top_link" ><span>Home</span></a></li>

            

            <li id="nav_RN" runat = "server" class="top"  ><a href="#nogo2" id="RN" class="top_link"><span class="down">Radni nalozi</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub">

    <li><a href="rn.aspx">Child1</a></li>

    <li><a href="#nogo19"> Child2</a></li>

    <li><a href="#nogo19"> Child3</a></li>

    <li><a href="#nogo20"> Child4</a></li>

    <li><a href="#nogo21"> Child5</a></li>

       </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

       </li>

    <li id="nav_vp" runat = "server" class="top"><a href="#nogo22" class="top_link"><span class="down">Parent 1</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

    <!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub">

    <li><a href="#nogo23"> Child1</a></li>

    <li><a href="#nogo24"> Child2</a></li>

    <li><a href="#nogo25"> Child3</a></li>

       </ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->

       </li> and so on....


    And when i loading the page i put this code:


        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            If User.IsInRole(ConfigurationManager.AppSettings("User").ToString) Then

                Me.Master.FindControl("nav_home").Visible = True

                Me.Master.FindControl("nav_RN").Visible = True

                Me.Master.FindControl("nav_vp").Visible = False

                Me.Master.FindControl("nav_admin").Visible = False

                Exit Sub

            ElseIf User.IsInRole(ConfigurationManager.AppSettings("PowerUser").ToString) Then

                Me.Master.FindControl("nav_home").Visible = True

                Me.Master.FindControl("nav_RN").Visible = True

                Me.Master.FindControl("nav_vp").Visible = True

                Me.Master.FindControl("nav_admin").Visible = False

                Exit Sub

            ElseIf User.IsInRole(ConfigurationManager.AppSettings("Administrator").ToString) Then

                Me.Master.FindControl("nav_home").Visible = True

                Me.Master.FindControl("nav_RN").Visible = True

                Me.Master.FindControl("nav_vp").Visible = True

                Me.Master.FindControl("nav_admin").Visible = True

                Exit Sub

            End If

            Response.Redirect("../no_access.aspx")

        End Sub


    This code is just for show or hide menu in css, you can also put this code for checking permissions to access


            If User.IsInRole(ConfigurationManager.AppSettings("Administrator").ToString) Or _

            User.IsInRole(ConfigurationManager.AppSettings("PowerUser").ToString) Then

    /* put something or control css menu */

                Exit Sub

            End If

            Response.Redirect("../no_access.aspx")

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 22, 2009 5:09 AM