简体   繁体   English

Windows Phone 8单一登录例外

[英]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. 我正在Windows Azure和Windows Phone 8应用程序上提供云服务。 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. 目前,在应用程序中,我正在编写用于处理单点登录服务的代码,选择提供程序后,用户ID将保存到受保护的存储中,并且用户会导航到登录成功页面。 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. 但是,有一个问题,当关闭应用程序并返回到应用程序时,有一种方法可以检查存储中的用户ID,这完全没有问题,但是当导航到应用程序主菜单时,会出现异常被try / catch捕获,并且用户被导航回登录页面,就像他们没有登录一样。

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;' 用户ID似乎未分配给对象,这是导致异常的原因,我尝试使用“ 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: 从隔离存储中检索用户ID后,我尚未声明一个字符串来保存用户ID,这是字符串:

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! 现在可以正常工作,因此,如果有人遇到相同的问题,希望对您有所帮助!

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

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