繁体   English   中英

Windows Phone 8单一登录例外

[英]Windows Phone 8 Single Sign On Exception

我正在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;”行解决此问题。 但这并没有改变问题。

在这里的任何人都知道为什么我的应用程序不允许我进入菜单页面吗?

谢谢

我已经解决了这个问题,相信我我会感到愚蠢!

从隔离存储中检索用户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));
        }
    }

现在可以正常工作,因此,如果有人遇到相同的问题,希望对您有所帮助!

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM