locked
access this page user1 or user2 or user3 RRS feed

  • Question

  • User2033107836 posted

    Hello

    I want to add to check if user1 or user2 or user3

    <%if (HttpContext.Current.User.Identity.Name == "user1")
                    { %>
                        <li><a href="#">Page 1</a></li>
                <%} %>

    how to do so in this above code

    Saturday, June 23, 2018 8:45 AM

Answers

  • User409696431 posted

    Do you have only three users, and know who they are?  If so you can use if statements or case statements.  You could simply extend the "if" you already are showing:

    <% if (HttpContext.Current.User.Identity.Name == "user1") {%>
       <li><a href="/page1">Page 1</a></li>
    <%  } else if (HttpContext.Current.User.Identity.Name == "user2") {%>
       <li><a href="/page2">Page 2</a></li>
    <%  } else if (HttpContext.Current.User.Identity.Name == "user3") {%>
       <li><a href="/page3">Page 3</a></li>
    <% } else { %>
       <li>No link here</li>
    <%  }%>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2018 2:37 PM

All replies

  • User-1171043462 posted

    It seems you want to implement Role Based Menu,

    Please refer my article: Role based security, Page access and Show/Hide Menu items based on Role in ASP.Net

    Sunday, June 24, 2018 7:15 AM
  • User409696431 posted

    Do you have only three users, and know who they are?  If so you can use if statements or case statements.  You could simply extend the "if" you already are showing:

    <% if (HttpContext.Current.User.Identity.Name == "user1") {%>
       <li><a href="/page1">Page 1</a></li>
    <%  } else if (HttpContext.Current.User.Identity.Name == "user2") {%>
       <li><a href="/page2">Page 2</a></li>
    <%  } else if (HttpContext.Current.User.Identity.Name == "user3") {%>
       <li><a href="/page3">Page 3</a></li>
    <% } else { %>
       <li>No link here</li>
    <%  }%>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2018 2:37 PM