UWP:获取当前的用户名以向用户提供权限 [英] UWP : Get the current UserName to provide rights to the user

查看:195
本文介绍了UWP:获取当前的用户名以向用户提供权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我为客户开发的应用程序,我需要获取当前的用户详细信息。
然后,我必须通过将 domain\login 对与包含所有授权用户的表进行比较来分配权限。

For an app that I develop for a customer, I need to get the current user details. Then I must assign rights by comparing the couple "domain\login" to a table containing all the authorized users.

我重用了@Sergiu Cojocaru提供的代码此处,我已经混合了一个官方示例( UserInfo )以获取更多详细信息:

I reuse the code given by @Sergiu Cojocaru here , that I have mixed with an official sample (UserInfo) to get more details:

IReadOnlyList<Windows.System.User> users = await Windows.System.User.FindAllAsync();

var current = users.Where(u => u.AuthenticationStatus == Windows.System.UserAuthenticationStatus.LocallyAuthenticated &&
                               u.Type == Windows.System.UserType.LocalUser).FirstOrDefault();

// user may have username
var data = await current.GetPropertyAsync(KnownUserProperties.AccountName);
string displayName = (string)data;

// or may be authenticated using hotmail/outlook
if (string.IsNullOrEmpty(displayName))
{
    string firstName = (string)await current.GetPropertyAsync(KnownUserProperties.FirstName);
    string lastName = (string)await current.GetPropertyAsync(KnownUserProperties.LastName);
    displayName = string.Format("{0} {1}", firstName, lastName);
}

但实际上我只得到 名字 KnownUserProperties 中的 姓氏。其他属性为空:

But actually I only get the "firstName" and the "lastName" from "KnownUserProperties". The others properties are empties:


  • providerName:空

  • accountName:空

  • guestHost:null

  • principalName:null

  • 域名:null

  • sipUri: null

  • providerName: null
  • accountName: null
  • guestHost: null
  • principalName: null
  • domainName: null
  • sipUri: null

=>这是正常现象吗?

=> Is this normal?

问题是预期的夫妇 domain\login 基于命令行 whoami 的结果,即得出的结果与 名字姓氏不同。

The problem is that the expected couple "domain\login" is based on the result of the command line "whoami", that doesn't give the same result that "firstName" and "lastName".

=>是否可以在应用程序中获得相同的结果?

=> Is there a way to get the same result in the app?

我指定我使用Hotmail帐户,但客户帐户必须基于Active Directory:我不知道这是否会改变任何内容...

I specify that I use a hotmail account but the customers accounts must be based on Active Directory: I don't know if this will change anything...

推荐答案

以获取有关域和域用户更改

To get information about domain and domain user change

var data = await current.GetPropertyAsync(KnownUserProperties.AccountName);

var data = await current.GetPropertyAsync(KnownUserProperties.DomainName);

对我来说,结果是:
ROM.EUROPE.TECHTEAM.COM\scojocar

on my side result is: ROM.EUROPE.TECHTEAM.COM\scojocar

这篇关于UWP:获取当前的用户名以向用户提供权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆