UWP:获取当前的用户名以向用户提供权限

编程入门 行业动态 更新时间:2024-10-24 23:23:03
本文介绍了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:获取当前的用户名以向用户提供权限

本文发布于:2023-10-30 04:03:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户提供   用户名   权限   UWP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!