本文介绍了检查PasswordVault /凭证管理器在加载时是否有应用数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嘿,我使用PasswordVault用于存储用户凭证在我的Windows 8应用。 我想什么应用做加载检查,看是否PasswordVault /凭据管理器已经为我的应用程序的存储值。如果不这样做我不希望它留在页面上,使用户可以登录,但如果凭证已经存在那么我想它直接进入第2页。 我用下面的代码尝试: 私人Windows.Security.Credentials.PasswordCredential GetCredentialFromLocker() { Windows.Security.Credentials.PasswordCredential凭证= NULL; 变种库=新Windows.Security.Credentials.PasswordVault(); VAR credentialList = vault.FindAllByResource(MYAPP); 如果(credentialList.Count大于0)如果(credentialList.Count == 1)凭证= credentialList [0]; ,否则 //用户selecor 返回凭证; } 然后在页面加载我 私人无效PAGE_LOADED(对象发件人,RoutedEventArgs E) { VAR loginCredential = GetCredentialFromLocker(); 如果(!loginCredential = NULL) this.Frame.Navigate(typeof运算(第2页)); ,否则 { loginBigButton.Visibility = Windows.UI.Xaml.Visibility.Visible; signUpButton.Visibility = Windows.UI.Xaml.Visibility.Visible; signUpTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible; } } 的问题是,如果没有存储与无凭证资源(MYAPP)的代码: VAR credentialList = vault.FindAllByResource(MYAPP); 收益率: 解决方案 Method FindAllByResource throws exception when there are no credentials for specified resource, so you need to wrap it with try catch block.Alternatively you can use 'RetrieveAll' which doesn't throw exception if there are no credentials stored and iterate over each returned PasswordCredential and check it's Resource property. 这篇关于检查PasswordVault /凭证管理器在加载时是否有应用数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-13 16:25