简体   繁体   English

通用Windows应用程序运行时组件未在使用Visual Studio 2015的Windows 10上产生UserIdentity

[英]Universal Windows Application Runtime component not resulting UserIdentity on Windows 10 using Visual Studio 2015

I am using Windows 10 machine and Visual studio 2015 for a project which has Windows Run time component and Universal Windows application (UWA). 我正在将Windows 10计算机和Visual Studio 2015用于具有Windows运行时组件和通用Windows应用程序(UWA)的项目。 UWA has reference of Windows Runtime component which perform a task to get UserIdentity (Window NT ID ie "DomainName/UserName") of logged in user. UWA具有Windows运行时组件的引用,该组件执行一项任务来获取已登录用户的UserIdentity(窗口NT ID,即“ DomainName / UserName”)。 UWA test project is created to debug the Runtime component. 创建UWA测试项目以调试运行时组件。 If we get UserIdentity in runtime component so we can use component reference to our Windows10 cordova project to get UserIdentity in javascript. 如果我们在运行时组件中获得UserIdentity,则可以使用对Windows10 cordova项目的组件引用来在javascript中获取UserIdentity。
Here we are facing issue where none of the code is working to get logged in user's DomainName/username. 在这里,我们面临的问题是,没有代码可用于登录用户的域名/用户名。 We have upgraded this code from Windows 8.1 to 10 wears this code is working great with Windows 8.1 but having issue in Windows 10. Below is the code which we are using to get UserIdentity: 我们已将此代码从Windows 8.1升级到10,因为该代码在Windows 8.1上可以很好地运行,但在Windows 10中却有问题。以下是我们用于获取UserIdentity的代码:

public sealed class getNTID
{
    public static IAsyncOperation<string> DownloadAsStringsAsync()
    {

        return Task.Run<string>(async () =>
        {

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

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


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

            return data.ToString();

        }).AsAsyncOperation();
    }
} 

We are getting empty string in data variable at the end. 最后,我们在数据变量中得到空字符串。 It would be great if someone share their exeperience or they have faced this kind of issue with mentioned platform. 如果有人分享他们的经验,或者他们在提到的平台上遇到过此类问题,那将是很棒的。

User class is new for windows 10 which is different with UserInformation in windows 8.1 you used. 用户类别是Windows 10的新增功能,与您使用的Windows 8.1中的UserInformation不同。 Getting access to a user's personal information is a privilege you have to request, so in your store app's Package.appxmanifest, you'll need to enable the User Account Information capability in the Capabilities tab. 访问用户的个人信息是您必须请求的特权,因此在商店应用的Package.appxmanifest中,您需要在“功能”选项卡中启用“用户帐户信息”功能。

When you call GetPropertyAsync , your user will get a permission prompt from the system as follows,accept that then you can get the permission. 当您调用GetPropertyAsync ,您的用户将从系统中获得如下的权限提示,即您可以获取该权限。 More details about capability please reference this document . 有关功能的更多详细信息,请参考此文档 在此处输入图片说明

For GetPropertyAsync method, if the property is missing or unavailable, an empty string is returned. 对于GetPropertyAsync方法,如果属性丢失或不可用,则返回一个空字符串。 So if you have already done but you still get null value maybe that the property is missing or unavailable. 因此,如果您已经完成但仍获得null值,则可能是该属性丢失或不可用。

Here is the result I got by running your code to get DomainName of current user (I also put the code in the windows run-time component). 这是我通过运行代码以获取当前用户的DomainName的结果(我还将代码放入Windows运行时组件中)。

在此处输入图片说明

More details please reference the official sample . 更多细节请参考官方样品

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Visual Studio 2015 的通用 Windows 10 应用程序 - Universal Windows 10 App Using Visual Studio 2015 Visual Studio 2015 + Windows 10部署 - Visual Studio 2015 + Windows 10 Deployment 无法使用Visual Studio 2015 RC在Windows 8.1+ Universal App中打开Windows Phone项目 - Can't open Windows Phone project in Windows 8.1+ Universal App using Visual Studio 2015 RC 永久加载Visual Studio 2015通用Windows XAML设计器表面 - Visual Studio 2015 Universal Windows XAML designer surface loading forever Visual Studio 2015空白应用程序(通用Windows):CS0731 - Visual Studio 2015 Blank App (Universal Windows): CS0731 Windows Phone模拟器未在Visual Studio 2015上运行(Windows 10专业版) - Windows Phone Emulator Not Running on Visual Studio 2015 (Windows 10 pro) Windows 10上的Visual Studio 2015中的Windows Phone 7.1 - Windows Phone 7.1 in Visual Studio 2015 on Windows 10 Visual Studio 2015错误Windows Phone应用程序 - Visual Studio 2015 Error Windows Phone Application 如何在Visual Studio 2015和Windows 10上运行DirectX代码示例? - How to run DirectX code samples on Visual Studio 2015 and Windows 10? Visual Studio 2012构建Windows 10应用程序? - Visual Studio 2012 build application for windows 10?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM