I want to get the username
or user id
of the currently logged in user in a UWP app. Below is the code that I am using but it returns null
.
var current = users.Where(p => p.AuthenticationStatus == UserAuthenticationStatus.LocallyAuthenticated && p.Type == UserType.LocalUser).FirstOrDefault();
var data = await current.GetPropertyAsync(KnownUserProperties.AccountName);
Username = (string)data;
This helped me. reference http://codegur.com/33736983/get-environment-variables-in-net-core-uwp