Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Best method for getting User.Identity.Firstname and other properties #5646


User avatar
0
sbenfares created

I would like to get FirstName and LastName of my users in my chstml views.

With asp.net identity we can have @User.identity.Name but only the name is exposed.

What is the cleanest method to get User.FirstName & Lastname (& other properties) in ANZ ?


4 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    hi,

    You can get it from SessionCache.

    See _Layout.cshtml.cshtml

     @{ var loginInfo = await SessionCache.GetCurrentLoginInformationsAsync(); }
     
     <span>@loginInfo.User.Name</span>
    

    Hope that helps

  • User Avatar
    0
    sbenfares created

    The name 'loginInfo' does not exist in the current context

  • User Avatar
    0
    alper created
    Support Team

    did you also write

    @{ var loginInfo = await SessionCache.GetCurrentLoginInformationsAsync(); }
    

    See your _Layout.cshtml.cshtml. It's already being used there.

  • User Avatar
    0
    sbenfares created

    I used the LoginInformations field in the HeaderViewModel, which contains exactly what i need.

    No need for the variable in page, best use with the ViewModel.

    Thanks for your help.