0

WAMS:微软认证。

http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-windows-store-dotnet-get-started-users/

从 Facebook 更改为 MicrosoftAccount

问题:当我单击后退箭头(退出登录)时,它应该仍然在 while 循环中并强制另一个弹出窗口永远不允许用户成功。相反,它击中了

catch (InvalidOperationException)


private MobileServiceUser user;
private async System.Threading.Tasks.Task AuthenticateAsync()
{
   while (user == null)
   {
       string message;
       try
       {
            user = await App.MobileService
            .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
            message = 
            string.Format("You are now logged in - {0}", user.UserId);
       }
       catch (InvalidOperationException)
       {
           message = "You must log in. Login Required";
       }

       var dialog = new MessageDialog(message);
       dialog.Commands.Add(new UICommand("OK"));
       await dialog.ShowAsync();
    }
}
4

1 回答 1

1

当您取消身份验证页面时,等待的调用LoginAsync将抛出 InvalidOperationException。这是意料之中的——你要求 SDK 登录,登录操作没有成功,所以你得到一个异常。抛出异常时,user不会发生对该字段的赋值,因此它保留其原始值 ( null),这就是循环继续的原因。如果在 catch 块中有断点,并在命中断点 (F5) 后继续,它应该再次提示身份验证。

于 2014-04-18T20:29:36.277 回答