locked
Show/hide problem RRS feed

  • Question

  • User-1104215994 posted

    Hi,

    I am trying to display authenticated user name on the right side of the menu after successful login.

    <ul class="nav navbar-nav navbar-right">
         <li><a>@User.Identity.Name</a></li>
    </ul>

    I would like to add Hello, user but if I write as follows, "Hello," is on the screen before login.

    <ul class="nav navbar-nav navbar-right">
         <li><a>Hello, @User.Identity.Name</a></li>
    </ul>

    How can I make "Hello," visible after successful login?

    Best Regards.

    Tuesday, September 3, 2019 11:30 AM

Answers

  • User753101303 posted

    Hi,

    Check User.Identity.IsAuthenticated to show this when the user logged in.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 3, 2019 11:43 AM
  • User61956409 posted

    Hi cenk1536,

    To achieve the requirement, as PatriceSc mentioned, we can check the value of User.Identity.IsAuthenticated, the code may look like below.

    <ul class="nav navbar-nav navbar-right">
        <li @Html.Raw(User.Identity.IsAuthenticated ? "" : "style='display:none'")><a>@User.Identity.Name</a></li>
        <li @Html.Raw(User.Identity.IsAuthenticated ? "style='display:none'" : "")><a>Hello, @User.Identity.Name</a></li>
    </ul>

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 4, 2019 1:56 AM

All replies

  • User753101303 posted

    Hi,

    Check User.Identity.IsAuthenticated to show this when the user logged in.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 3, 2019 11:43 AM
  • User-1104215994 posted

    Thank you again.

    Tuesday, September 3, 2019 11:53 AM
  • User61956409 posted

    Hi cenk1536,

    To achieve the requirement, as PatriceSc mentioned, we can check the value of User.Identity.IsAuthenticated, the code may look like below.

    <ul class="nav navbar-nav navbar-right">
        <li @Html.Raw(User.Identity.IsAuthenticated ? "" : "style='display:none'")><a>@User.Identity.Name</a></li>
        <li @Html.Raw(User.Identity.IsAuthenticated ? "style='display:none'" : "")><a>Hello, @User.Identity.Name</a></li>
    </ul>

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 4, 2019 1:56 AM