locked
How To Show Bootstrap Navigation Menu Based On Asp.net Log In User RRS feed

  • Question

  • User2033107836 posted

    Hello

    I use this in my aspx page masterpage.maser

    https://www.w3schools.com/bootstrap/bootstrap_navbar.asp

    For Example I Have Page1, Pag2, Page3

    If user "John" Login from asp.net login then i want to show only Page1

    If user "Raja" Login from asp.net login then i want to show only Page2 and Page3

    How To Do Using Asp.net 2.0 C#

    Thanking You

    Thursday, March 8, 2018 9:50 AM

Answers

  • User475983607 posted

    Use code blocks. This example assumes you are using builtin ASP authentication.

        <nav class="navbar navbar-default">
          <div class="container-fluid">
            <div class="navbar-header">
              <a class="navbar-brand" href="#">WebSiteName</a>
            </div>
            <ul class="nav navbar-nav">
              <li class="active"><a href="#">Home</a></li>
                <%if (HttpContext.Current.User.Identity.Name == "John")
                    { %>
                        <li><a href="#">Page 1</a></li>
                <%} %>
    
                 <%if (HttpContext.Current.User.Identity.Name == "Raja")
                    { %>
                        <li><a href="#">Page 2</a></li>
                        <li><a href="#">Page 3</a></li>
                <%} %>
    
            </ul>
          </div>
        </nav>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 8, 2018 1:56 PM

All replies

  • User475983607 posted

    Use code blocks. This example assumes you are using builtin ASP authentication.

        <nav class="navbar navbar-default">
          <div class="container-fluid">
            <div class="navbar-header">
              <a class="navbar-brand" href="#">WebSiteName</a>
            </div>
            <ul class="nav navbar-nav">
              <li class="active"><a href="#">Home</a></li>
                <%if (HttpContext.Current.User.Identity.Name == "John")
                    { %>
                        <li><a href="#">Page 1</a></li>
                <%} %>
    
                 <%if (HttpContext.Current.User.Identity.Name == "Raja")
                    { %>
                        <li><a href="#">Page 2</a></li>
                        <li><a href="#">Page 3</a></li>
                <%} %>
    
            </ul>
          </div>
        </nav>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 8, 2018 1:56 PM
  • User2033107836 posted

    Hi

    Thanks for your code

    how to give single page two user or more..?

    Thanking You

    Friday, March 9, 2018 2:00 PM
  • User475983607 posted

    Hi

    Thanks for your code

    how to give single page two user or more..?

    Thanking You

    Your question is unclear.  My best guess is you are asking for a production design rather than how to.  Take advantage of a UserControl to encapsulate the logic.  I would use roles rather than usernames but I don't know your application requirements.

    Keep in mind that ASP.NET 2.0 comes with everything needed to create a menus and secure resources.  It is just a matter of reading the docs.  There are tons and tons of docs as ASP.NET 2.0 is a very mature framework.

    https://msdn.microsoft.com/en-us/library/ecs0x9w5.aspx

    https://msdn.microsoft.com/en-us/library/305w735z.aspx

    https://msdn.microsoft.com/en-us/library/ms366731.aspx

    Friday, March 9, 2018 2:10 PM