2014-04-02 50 views
0

我正在制作Windows Azure和Windows Phone 8应用程序上的云服务。在我编写处理单点登录服务代码的应用程序中,选择提供程序后,用户标识将被保存到受保护的存储中,并且用户将被导航到登录成功页面。然而,在关闭应用程序并重新进入应用程序时,有一个问题,那就是检查存储器中的用户标识,但根本没有问题,但是当导航到应用程序主菜单时,出现异常通过一个try/catch捕获,并且用户导航回到登录页面,如果他们还没有登录Windows Phone 8单点登录异常

这是检查用户ID的方法:

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'这行来解决这个问题。但这对问题没有影响。

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

感谢

+0

请粘贴异常消息文本,以便我们获得关于异常本身的更多细节。 我假设App.MobileService.CurrentUser为空,因此你会得到一个异常。 – eX0du5

+0

出于某种原因,应用程序甚至在现在打开时甚至不会检索用户标识。但原来的错误是(如果我记得)'值没有设置为对象的实例' – BenMcGrath

+0

例外文本是: + \t \t $例外\t {System.NullReferenceException:未将对象引用设置为对象的实例。 at TakeMyPillsApp.MainPage.OnNavigatedTo(NavigationEventArgs e)} \t System.Exception {System.NullReferenceException} – BenMcGrath

回答

0

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

它已经从独立存储检索后,我还没有宣布一个字符串来保存用户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)); 
     } 
    } 

这个现在可以工作,所以我希望它有帮助,如果任何人有同样的问题!