How to change the welcome message to log in!

1

I'm developing an ASP.NET MVC application, by default it already comes with a pre-defined template, however when I log in to the application it displays the message "Hello [email protected]!", but I wanted that instead of the email appear the name of the person logged, since I created this field in the database, to store the name in the screen of Register. Could someone help me with this?

Below the section responsible for displaying the message on the screen:

 using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
    {
    @Html.AntiForgeryToken()

    <ul class="nav navbar-nav navbar-right">
        <li>
            @Html.ActionLink("Olá " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
        </li>
        <li><a href="javascript:document.getElementById('logoutForm').submit()">Sair</a></li>
    </ul>
    }
    
asked by anonymous 11.04.2018 / 19:44

1 answer

0

To recover the Name property of the logged in user, just call User.Identity.Name

using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
    @Html.AntiForgeryToken()

    <ul class="nav navbar-nav navbar-right">
        <li>
            @Html.ActionLink("Olá " + User.Identity.Name + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
        </li>
        <li><a href="javascript:document.getElementById('logoutForm').submit()">Sair</a></li>
    </ul>
}

When you call User.Identity you will have access to all properties of the logged in user.

    
12.04.2018 / 00:41