C# UWP-WebAuthenticationBroker在发布模式下的设备上崩溃
我正在制作一个使用OAuth2的UWP应用程序。我使用的是WebAuthenticationBroker类,在设备上进行调试时也可以,但更改为release并运行会导致应用程序在应该打开auth对话框时崩溃。 这是代码,几乎是他们在MSDN上给你的样板文件C# UWP-WebAuthenticationBroker在发布模式下的设备上崩溃,c#,oauth-2.0,uwp,C#,Oauth 2.0,Uwp,我正在制作一个使用OAuth2的UWP应用程序。我使用的是WebAuthenticationBroker类,在设备上进行调试时也可以,但更改为release并运行会导致应用程序在应该打开auth对话框时崩溃。 这是代码,几乎是他们在MSDN上给你的样板文件 try { var webAuthenticationResult = await Windows.Security.Authentication.Web.WebAuthenticationBroker.Authent
try {
var webAuthenticationResult = await Windows.Security.Authentication.Web.WebAuthenticationBroker.AuthenticateAsync(Windows.Security.Authentication.Web.WebAuthenticationOptions.None, startURI);
switch (webAuthenticationResult.ResponseStatus) {
case Windows.Security.Authentication.Web.WebAuthenticationStatus.Success:
// Successful authentication.
var uri = new Uri(webAuthenticationResult.ResponseData);
var index = uri.Query.IndexOf('=') + 1;
code = uri.Query.Substring(index);
_accessToken = await GetAccessToken(code);
vault.Add(new PasswordCredential("myApp", "token", Token));
break;
case Windows.Security.Authentication.Web.WebAuthenticationStatus.ErrorHttp:
// HTTP error.
throw new HttpRequestException(webAuthenticationResult.ResponseErrorDetail.ToString());
default:
// Other error.
throw new Exception(webAuthenticationResult.ResponseData.ToString());
}
} catch (Exception ex) {
// Authentication failed. Handle parameter, SSL/TLS, and Network Unavailable errors here.
throw ex;
}
事实证明,我需要为这个特定API的end URI传递第三个参数。不确定为什么在调试中可以,但是。。。现在一切似乎都很好。只需要去掉我手机顶部的边距。我做了一件事,在项目的属性中,我选择了删除所有数据的选项。不过我不确定这是否有什么作用。你在App.Entering/LeavingBackground中有什么东西吗?@Romasz我没有,这是大多数谷歌用户发给我的。事实证明,我需要为end-URI传递第三个参数。不确定为什么在调试中可以,但是。。。现在一切似乎都很好。只需要去掉我手机顶部的边距。我做了一件事,在项目的属性中,我选择了删除所有数据的选项。我不确定这是否有什么作用。