我正在为 Windows Phone 8 开发一个应用程序。我正在尝试使用这个非常简单的示例来实现身份验证:http: //www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-users -wp8/,然后是这个:http: //www.windowsazure.com/en-us/develop/mobile/tutorials/authorize-users-in-scripts-wp8/。我的应用程序必须继续能够验证和控制我的应用程序用户的访问权限。具体来说,我的问题在这里:
private async System.Threading.Tasks.Task Authenticate()
{
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 e)
{
message = e + "You must log in. Login Required";
}
MessageBox.Show(message);
}
}
这与两个教程的代码一样多。它启动登录屏幕,user = await App.MobileService
.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
但在接受登录凭据后,它开始显示错误消息,即:
+ $exception {System.InvalidOperationException: Cannot start a login operation because login is already in progress.
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.<SendLoginAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at SeeThrough.MainPage.<Authenticate>d__7.MoveNext()} System.Exception {System.InvalidOperationException}
它重复这个过程,因为“用户”永远不会被分配,因为“登录已经在进行中”的情况。我在网上找不到任何可以帮助的东西,我已经搜索了这个错误,并且只得到了 4 个确切问题的命中,这些问题是 github 代码的一部分,据我所知没有任何帮助。