我正在製作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'這行來解決這個問題。但這對問題沒有影響。
這裏的任何人都明白爲什麼我的應用程序不會讓我進入菜單頁面嗎?
感謝
請粘貼異常消息文本,以便我們獲得關於異常本身的更多細節。 我假設App.MobileService.CurrentUser爲空,因此你會得到一個異常。 – eX0du5
出於某種原因,應用程序甚至在現在打開時甚至不會檢索用戶標識。但原來的錯誤是(如果我記得)'值沒有設置爲對象的實例' – BenMcGrath
例外文本是: + \t \t $例外\t {System.NullReferenceException:未將對象引用設置爲對象的實例。 at TakeMyPillsApp.MainPage.OnNavigatedTo(NavigationEventArgs e)} \t System.Exception {System.NullReferenceException} – BenMcGrath