简体   繁体   中英

Windows Phone 8 Single Sign On Exception

I'm in the process of making a cloud service on Windows Azure and a Windows Phone 8 app. In the app at the moment I am writing the code to deal with a single sign on service, after selecting a provider, the user ID is saved to protected storage and the user is navigated to a login success page. There is a problem however, when closing the app and going back into it, there is a method which checks for a user ID in storage, this is found no problem at all but when coming to navigate to the apps main menu, an exception is caught by a try/catch and the user is navigated back to the login page as if they are not logged in.

This is the method that checks for a userid:

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));
        }
    }

The user ID appears to not be assigned to an object which is the reason for an exception, I have tried to solve this with the line 'FilePath = App.MobileService.CurrentUser.UserId;' but this has not made a difference to the problem.

Is it apparent to anyone on here why my app will not let me get to the menu page?

Thanks

I have solved this problem, and believe me I feel stupid!

I had not declared a string to hold the user id after it had been retrieved from isolated storage, this is the string:

private string storedUser;

I also changed the method slightly to reflect the new string:

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));
        }
    }

This now works, so I hope it helps if anyone has the same problem!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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