蔚蓝 Xamarin.Android "You must be logged in to use this application"

Azure with Xamarin.Android "You must be logged in to use this application"

我最近开始为我的 Final Year Project 学习移动开发,我正在使用 Xamarin.Android 和 Azure 移动服务开发一个 Android 应用程序。 我已经创建了一个测试数据库并在那里创建了一个条目,试图让我的 Android 应用程序连接到数据库并检索该条目。我这样做是为了了解如何建立连接和检索数据,然后我将从那里开始正确修改。 这就是我的模型 class 的样子(请注意 JSON 属性的命名与我数据库中的列名完全相同。

using Newtonsoft.Json;

namespace com.parkkl.intro.Models
{
    class TestTable
    {
        public int Id { get; set; }

        [JsonProperty(PropertyName = "UserName")]
        public string UserName { get; set; }
        [JsonProperty(PropertyName = "deleted")]
        public bool Deleted { get; set; }
        [JsonProperty(PropertyName = "version")]
        public string Version { get; set; }
        [JsonProperty(PropertyName = "createdAt")]
        public string Creation { get; set; }
        [JsonProperty(PropertyName = "updatedAt")]
        public string Updated { get; set; }
    }
}

这就是我的 activity 的样子

using Android.App;
using Microsoft.WindowsAzure.MobileServices;
using Android.OS;
using com.parkkl.intro.Models;
using System.Collections.Generic;
using Android.Widget;

namespace com.parkkl.intro
{
    [Activity(Label = "ParkKL", MainLauncher = false, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        #region Variables
        public static MobileServiceClient client = new MobileServiceClient
            (@"http://parkkl.azurewebsites.net/");
        private IMobileServiceTable<TestTable> test = null;
        private List<TestTable> testItems;
        #endregion

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            test = client.GetTable<TestTable>();

            testItems = new List<TestTable>();

            GetData();

        }

        public async void GetData()
        {
            var collection = await test.Where(user => user.Id == 1).ToCollectionAsync();

            foreach (var item in collection)
            {
                testItems.Add(
                    new TestTable
                    {
                        Id = item.Id,
                        UserName = item.UserName,
                        Deleted = item.Deleted,
                        Version = item.Version,
                        Creation = item.Creation,
                        Updated = item.Updated,
                    });
            }
            var finalItem = collection[0];
            TextView text = (TextView)FindViewById(Resource.Id.TextFromDB);
            text.Append(finalItem.UserName);
        }
    }
}

现在的问题是,每次我尝试部署应用程序时,它都会抛出此异常

Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: You must be logged in to use this application

在我的 Azure 应用服务中,我已禁用所有身份验证,但仍然出现此错误。我想知道问题出在哪里?!非常感谢您的帮助。

编辑:我想我发现了问题,这是对 table 本身赋予的权限。但是,我仍在寻找一种正确验证我的应用程序的方法

查看 http://aka.ms/zumobook 一书,了解有关如何处理身份验证的详细信息。