【发布时间】:2013-03-22 10:11:34
【问题描述】:
我在IsolatedStorage 中有一个文件。如果文件存在,我想重定向到登录页面或创建帐户页面。
如果文件不存在,应用程序会转到创建页面,创建并保存密码,然后应用程序重定向到登录页面。但是,如果IsolatedStorage 中的文件存在,则不会定向。
private void fileExists()
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if (store.FileExists("passwordFile"))
{
//NavigationService.Navigate(new Uri("/Login.xaml", UriKind.Relative));
MessageBox.Show("Should be redirecting here");
}
else
{
MessageBox.Show("Welcome. Please create an account. Ensure that you remember your password!");
}
}
实际消息确实显示,因此它被调用,如果文件不存在,则执行 else,因此我的逻辑是合理的。
FileExists() 函数在这里被调用。
public MainPage()
{
InitializeComponent();
fileExists();
}
另一个重定向发生在这里
if ((password1.Password == password2.Password) & (password1.Password.Trim().Length > 0 || password2.Password.Trim().Length > 0))
{
byte[] PasswordByte = Encoding.UTF8.GetBytes(password1.Password);
byte[] ProtectedPassword = ProtectedData.Protect(PasswordByte, null);
this.WritePasswordToFile(ProtectedPassword);
NavigationService.Navigate(new Uri("/Login.xaml", UriKind.Relative));
}
错误是System.NullReferenceException,但未在用户代码中处理。
【问题讨论】:
-
这里是真正的题外话,请散列或加密您的密码文件,用一些花哨的编码和修改的 WP8 轻松访问隔离存储
-
我会的,这只是一个开始!我昨天刚开始使用 C# 和 WP,加密是该项目的重要组成部分,但我不会在几周内看到它。不过谢谢!
标签: c# navigation windows-phone isolatedstorage