简体   繁体   中英

Resolving current user in UWP app

Some basic informations about the UWP:

  • Capabilities turned on: Internet (Client), User Account Information, Webcam
  • No declarations
  • Target version: Windows 10 Anniversary Edition
  • Min Version: Windows 10 (10.0)
  • Build Platform: x64

Here is my code to retrieve user informations:

public async Task ResolveUserAsync()
{
    if (_currentUserInfo != null)
    {
        return;
    }
    var users = await User.FindAllAsync(UserType.LocalUser);
    var desiredProperties = new[]
    {
        KnownUserProperties.FirstName, KnownUserProperties.LastName, KnownUserProperties.ProviderName, KnownUserProperties.AccountName, KnownUserProperties.GuestHost,
        KnownUserProperties.PrincipalName, KnownUserProperties.DomainName, KnownUserProperties.SessionInitiationProtocolUri
    };
    _currentUserInfo = await users.FirstOrDefault().GetPropertiesAsync(desiredProperties);
    foreach (var prop in _currentUserInfo)
    {
        Debug.WriteLine($"{prop.Key}: {prop.Value}");
    }
}

The output in Debug console:

lastName:
firstName:
accountName: 
domainName: 
providerName: 
sipUri: 
principalName: 
guestHost: 

The app runs on a tablet which is member of a classic AD and I cannot figure out, why those values are empty. The app asks for confirmation on user details in the UI.

Side notes: If I test this on a machine where I'm logged in with an AzureAD account this code will fill in firstName and lastName only.

不完全确定此行为最近是否改变,但是在过去,这取决于您作为用户的隐私设置(设置->隐私->帐户信息->顶部切换开关)

I had a similar problem in my App. After I turned on the "Enterprise Authentication" Feature in the app manifest, at least the principalName property was filled

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM