簡體   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