Windows Phone 8单点登录例外

时间:2014-04-02 13:02:50

标签: c# azure windows-phone-8

我正在使用Windows Azure和Windows Phone 8应用程序制作云服务。在应用程序中,我正在编写处理单点登录服务的代码,在选择提供程序后,用户ID将保存到受保护的存储中,用户将导航到登录成功页面。然而,有一个问题,当关闭应用程序并返回它时,有一种方法可以检查存储中的用户ID,这一点没有问题,但是当导航到应用程序主菜单时,一个例外是通过try / catch捕获并且用户被导航回登录页面,就好像他们没有登录一样。

这是检查用户标识的方法:

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        try
        {
            byte[] ProtectedPinByte = this.ReadPinFromFile();
            byte[] PinByte = ProtectedData.Unprotect(ProtectedPinByte, null);
            App.MobileService.CurrentUser.UserId = Encoding.UTF8.GetString(PinByte, 0, PinByte.Length);
            FilePath = App.MobileService.CurrentUser.UserId;
            NavigationService.Navigate(new Uri("/Views/Menu.xaml", UriKind.Relative));
        }
        catch
        {
            NavigationService.Navigate(new Uri("/LoginScreens/LoginSelection.xaml", UriKind.Relative));
        }
    }

用户ID似乎没有分配给一个异常原因的对象,我试图用'FilePath = App.MobileService.CurrentUser.UserId;'这一行来解决这个问题。但这并没有对问题产生影响。

这里的任何人都明白为什么我的应用程序不会让我进入菜单页面?

由于

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,相信我,我觉得自己很蠢!

在从隔离存储中检索用户ID后,我没有声明一个字符串来保存用户ID,这是字符串:

private string storedUser;

我也稍微改变了方法以反映新字符串:

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        try
        {
            byte[] ProtectedPinByte = this.ReadPinFromFile();
            byte[] PinByte = ProtectedData.Unprotect(ProtectedPinByte, null);
            storedUser = Encoding.UTF8.GetString(PinByte, 0, PinByte.Length);
            NavigationService.Navigate(new Uri("/Views/Menu.xaml", UriKind.Relative));
        }
        catch
        {
            NavigationService.Navigate(new Uri("/LoginScreens/LoginSelection.xaml", UriKind.Relative));
        }
    }

这现在有效,所以我希望如果有人遇到同样的问题会有帮助!