[英]UWP : Get the current UserName to provide rights to the user
对于我为客户开发的应用程序,我需要获取当前的用户详细信息。 然后,我必须通过将夫妇“ domain \\ login ”与包含所有授权用户的表进行比较来分配权限。
我在这里重用@Sergiu Cojocaru给出的代码,我将其与官方示例( UserInfo )混合在一起以获取更多详细信息:
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 ”获得“ firstName ”和“ lastName ”。 其他属性为空:
=>这正常吗?
问题在于,预期的对“ domain \\ login ”是基于命令行“ whoami ”的结果,与“ firstName ”和“ lastName ”的结果不同。
=>有没有办法在应用程序中获得相同的结果?
我指定使用Hotmail帐户,但客户帐户必须基于Active Directory:我不知道这是否会更改任何内容...
获取有关域和域用户更改的信息
var data = await current.GetPropertyAsync(KnownUserProperties.AccountName);
至
var data = await current.GetPropertyAsync(KnownUserProperties.DomainName);
在我这边的结果是:ROM.EUROPE.TECHTEAM.COM \\ scojocar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.