我有一个代码在几天前无法使用:这是一个xamarin.android活动代码
[Activity(Label = "AuthSample", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
Button login;
//Mobile Service Client reference
private MobileServiceClient client;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
client = new MobileServiceClient("https://XXXXXXX.azurewebsites.net");
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
login = FindViewById<Button>(Resource.Id.buttonLoginUser);
login.Click += onLoginClick;
}
private async void onLoginClick(object sender, EventArgs e)
{
// Load data only after authentication succeeds.
if (await Authenticate())
{
}
}
// Define a authenticated user.
private MobileServiceUser user;
private async Task<bool> Authenticate()
{
var success = false;
try
{
// Sign in with Microsoft login using a server-managed flow.
user = await client.LoginAsync(this,
MobileServiceAuthenticationProvider.MicrosoftAccount);
CreateAndShowDialog(string.Format("you are now logged in - {0}",
user.UserId), "Logged in!");
success = true;
}
catch (Exception ex)
{
CreateAndShowDialog(ex, "Authentication failed");
}
return success;
}
private void CreateAndShowDialog(Exception exception, String title)
{
CreateAndShowDialog(exception.Message, title);
}
private void CreateAndShowDialog(string message, string title)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetMessage(message);
builder.SetTitle(title);
builder.Create().Show();
}
}
我完成了tutorial中的所有指示。 LoginAsync将我重定向到Microsoft登录页面,我能够进行身份验证,并且在成功进行身份验证后,我收到此错误:“由于发生内部服务器错误,无法显示该页面”
我正在使用3.1 azure sdk版本
答案 0 :(得分:0)
根据您的说明,我假设您可以按照以下步骤解决此问题。
对于Node.js后端
如果不存在,您可以利用App Service Editor或kudu在根文件夹(D:\ home \ site \ wwwroot)下创建iisnode.yml
文件。然后为enable logging to debug a Node.js web app in azure app service添加以下设置:
loggingEnabled: true
logDirectory: iisnode
此外,这里有关于enable node.js日志记录的类似issue,您可以参考它。另外,有关kudu和app服务编辑器的更多详细信息,请参阅here。
适用于C#后端
您可以编辑App_Start\Startup.MobileApp.cs
文件并按如下方式配置IncludeErrorDetailPolicy
以捕获错误详细信息:
HttpConfiguration config = new HttpConfiguration();
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
以简单的方式,您可以通过浏览器访问https://{your-app-name}.azurewebsites.net/.auth/login/{provider-name}
,然后查看详细的错误消息以找到特定的错误。
<强>更新强>
根据您的地址,我检查了您的应用,发现我可以通过浏览器使用我的Microsoft帐户登录。然后我检查了你的表端点,发现了以下错误:
https://{your-app-name}.azurewebsites.net/tables/todoitem?ZUMO-API-VERSION=2.0.0
消息:“发生了错误。”, exceptionMessage:“建立与SQL Server的连接时发生与网络相关或特定于实例的错误。未找到服务器或无法访问服务器。验证实例名称是否正确以及SQL Server是否配置为允许远程服务器连接。(提供程序:SQL网络接口,错误:52 - 无法找到本地数据库运行时安装。验证是否已正确安装SQL Server Express并且已启用本地数据库运行时功能。)” exceptionType:“System.Data.SqlClient.SqlException”,
众所周知,在跟随快速入门为后端创建数据存储时,下载C#后端,然后将后端部署到moible app。此时,通过azure门户创建的连接字符串不会暴露给您的ASP.NET应用程序,默认连接字符串将使用localdb,您需要在部署到azure移动应用程序之前编辑Web.config
文件如下:
<connectionStrings>
<add name="MS_TableConnectionString" connectionString="Data Source=tcp:{your-sqlserver-name}.database.windows.net,1433;Initial Catalog={db-name};User ID={user-id};Password={password}" providerName="System.Data.SqlClient" />
</connectionStrings>
或者在通过VS将应用程序部署到azure移动应用程序时配置连接字符串,如下所示:
答案 1 :(得分:0)
似乎在azure或Microsoft身份验证中存在问题。 经过两天的挫折,一切都开始重新开始了!!