gpt4 book ai didi

c# - 如何处理 Xamarin Forms 的 Azure 移动应用程序中的用户 token ?

转载 作者:太空狗 更新时间:2023-10-30 00:38:47 25 4
gpt4 key购买 nike

我正在为 Azure 移动应用开发具有 .NET 背景的 Xamarin Forms 应用。我在使用客户端时遇到了一些问题,我想知道我应该如何处理用户 token MobileServiceUser。

我应该如何保留 token 的数据并通过客户端应用程序使用它?

我成功登录了用户。现在用户转到另一个页面并尝试检索信息。我为每个表/对象创建了一个像“TodoItemManager”这样的管理器。所以现在我正在使用 FoodItemManager,但 MobileServiceClient 的 MobileServiceUser 为空,因为我使用 LoginItemManager 记录了用户。所以数据丢失了。我应该为整个应用程序使用一个管理器来保持 MobileServiceUser 存活吗?什么是最好的方法?

非常感谢。

最佳答案

您应该为整个应用程序使用单例 MobileServiceClient 对象,这将在您的所有 View 中保留已登录的用户。创建多个客户端对象通常不是一个好主意。

如果您还想在应用重新启动时保留用户 token ,您可以使用 Xamarin.Auth 库,它将安全地存储 token 。下面是 Xamarin.Forms 的示例:https://github.com/azure-appservice-samples/ContosoMoments/blob/master/src/Mobile/ContosoMoments/Helpers/AuthStore.cs .

关于c# - 如何处理 Xamarin Forms 的 Azure 移动应用程序中的用户 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38395688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com