How to change the welcome message when logging in!

Asked

Viewed 82 times

1

i am developing an application in ASP.NET MVC, by default it already comes with a predefined template, however when logging in the application is displayed the message "Hello [email protected] !" but I wanted instead of appearing the email to be displayed the name of the logged in person, because I created this field in the database, to store the name on the Register screen. 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>
    }
  • Yes, someone could help. What is the snippet of code that puts the message on screen?

  • @Renan I did not think it was necessary to include the excerpt, because it is standard in all projects Asp net mvc when we create!

  • It is common to customize this code... Anyway, I think there is now enough information.

  • @Renan how would this customization, do you have any idea? The most %&*@ is that I’ve already done this, so it’s a long time and I don’t have the project to look at!

  • I’m also rusty. I hope you get a good answer. If I don’t get one by tomorrow, I can put a reward on this question. Anyway... The ideal would be for you to load an object that represents the user through the MVC framework of ASP.NET. Place this object on the page and all its fields will be available in the frontend.

  • You want the full name or Username?

  • It can be the full name, no problem, I just want it to not be the email, because the login here in this case is not done with username only with the same email, It was the request of the company, if the login was done this way would be easier!

Show 2 more comments

1 answer

0


To reclaim the property Name 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 it’s called the User.Identity you will have access to all user properties logged in.

  • Not that my friend, continues to display the email, I think I will have to change this following line in my Register accountController: var user = new ApplicationUser { UserName = model.Email, Email = model.Email };

  • I was going to ask you just this, if you were not saving the email on the name, where you save the user name?

  • that’s right the Username will have to receive model.Full name and model. Email.... problem solved... thanks to everyone who helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.