gpt4 book ai didi

c# - Windows应用程序中的身份验证 "Cannot work with a MobileServiceClient that does not specify a gateway URI."

转载 作者:行者123 更新时间:2023-11-30 16:52:24 25 4
gpt4 key购买 nike

我正在尝试在我的通用应用程序中实现用户身份验证(不使用移动服务),如 this 中所示。文章。但是我收到以下错误:

Cannot work with a MobileServiceClient that does not specify a gateway URI.

由于我没有使用移动服务进行身份验证并在客户端通用应用程序中执行此操作,因此我不确定此处的网址是什么。目前,“http://MyApp.azurewebsites.net ”是我在 Azure Portal 中拥有的后端应用程序的 URL。 (浏览全部 > MyApp > 设置 > url)。

在我共享的 App.xaml.cs 中:

//Problem may be here as per my understanding
public static MobileServiceClient MobileService =
new MobileServiceClient("http://MyApp.azurewebsites.net");

在我共享的 MainPage.cs 中:

private async System.Threading.Tasks.Task AuthenticateAsync()
{
string message;

// This sample uses the Microsoft provider.
var provider = "MicrosoftAccount";

// Use the PasswordVault to securely store and access credentials.
PasswordVault vault = new PasswordVault();
PasswordCredential credential = null;
while (credential == null)
{
try
{
// Try to get an existing credential from the vault.
credential = vault.FindAllByResource(provider).FirstOrDefault();
}
catch (Exception)
{
// When there is no matching resource an error occurs,
// which we ignore.
}
if (credential != null)
{
// Create a user from the stored credentials.
user = new MobileServiceUser(credential.UserName);
credential.RetrievePassword();
user.MobileServiceAuthenticationToken = credential.Password;

// Set the user from the stored credentials.
App.MobileService.CurrentUser = user;

try
{
// Try to return an item now to determine
// if the cached credential has expired.
await App.MobileService
.GetTable<TodoItem>().Take(1).ToListAsync();
}
catch (MobileServiceInvalidOperationException ex)
{
if (ex.Response.StatusCode ==
System.Net.HttpStatusCode.Unauthorized)
{
// Remove the credential with the expired token.
vault.Remove(credential);
credential = null;
continue;
}
}
}
else
{
try
{
// Login with the identity provider.
// Here I am getting the exception.
user = await App.MobileService.LoginAsync(provider);

// Create and store the user credentials.
credential = new PasswordCredential(provider,
user.UserId, user.MobileServiceAuthenticationToken);
vault.Add(credential);
}
catch (MobileServiceInvalidOperationException ex)
{
message = "You must log in. Login Required";
}
}
message = string.Format("You are now logged in - {0}", user.UserId);
var dialog = new MessageDialog(message);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}

那么什么是网关 Uri,我做错了什么,以及如何在没有 Azure 移动服务(托管在 azure 上的 MVC 项目)的情况下仅在应用程序中实现身份验证。

最佳答案

应用程序需要有关联的网关。如需进一步阅读,checkout this article on the Azure website 。您将需要这样的代码:

public static MobileServiceClient MobileService = new MobileServiceClient(
mobileAppUri: "https://mvp2015mobileapp.azurewebsites.net",
gatewayUri: "https://mvp2015b14929cfc35019b24a7daaf694.azurewebsites.net",
applicationKey: string.Empty);

查找现有的应用服务网关

从portal.azure.com,打开您的移动应用程序,然后单击其资源组链接。资源组边栏选项卡打开后,单击其摘要面板。如果您已有网关,它将出现在列表中。

Gateway

创建新的应用服务网关

从portal.azure.com,打开您的移动应用程序,选择“设置”,然后选择“移动用户身份验证”。您将能够从那里创建一个新的网关。以下屏幕截图显示了创建网关的位置(还显示了资源组链接。)

Create Gateway

检索网关 URL

找到网关后,您可以获取其 URL。

Gateway URL

关于c# - Windows应用程序中的身份验证 "Cannot work with a MobileServiceClient that does not specify a gateway URI.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32611148/

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