嘿,我正在使用 PasswordVault 在我的 Windows 8 应用程序中存储用户凭据。
我希望应用程序在加载时执行的操作是检查 PasswordVault/凭据管理器是否已经为我的应用程序存储了值。如果不希望它留在页面上以便用户可以登录,但如果凭据已经存在,那么我希望它直接进入第 2 页。
我尝试使用以下代码:
private Windows.Security.Credentials.PasswordCredential GetCredentialFromLocker()
{
Windows.Security.Credentials.PasswordCredential credential = null;
var vault = new Windows.Security.Credentials.PasswordVault();
var credentialList = vault.FindAllByResource("MYapp");
if (credentialList.Count > 0)
if (credentialList.Count == 1)
credential = credentialList[0];
else
// User selecor
return credential;
}
然后在页面加载时我有
private void Page_Loaded(object sender, RoutedEventArgs e)
{
var loginCredential = GetCredentialFromLocker();
if (loginCredential != null)
this.Frame.Navigate(typeof(page2));
else
{
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");
产量:
WinRT 信息:在 Vault 中找不到凭据
附加信息:未找到元素。