'Retrieve the windows user which connects to a linux server

I have a web application deployed on a linux server. When a user connects to this server, we want to display its username on the banner of the page.

To make things easy for sample, the razor homepage is like this :

<div>
 @userName
</div>

@code {
  private string userName;

  protected override void OnInitialized()
    {   
        PowerShell powerShell = PowerShell.Create();
        powerShell.AddCommand("whoami");
        var result = powerShell.Invoke();

        if (result.Count > 0)
        {
           userName = result[0].BaseObject.ToString();
        }
        else
        {
            userName = string.Empty;    
        }
        base.OnInitialized();
    }

}

And if I execute this, I wont get 'Jérémy J' as I am the person which connects to the server but I retrieve the name of the logged person on the server (here 'LinServ0Dev'), but I need to retrieve 'Jérémy J'...

What is the command in PowerShell (or other technic) to retrieve the name of the user which connect to the server ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source