[英]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.