gpt4 book ai didi

Azure Redis,如何使用 Microsoft Azure 管理库 (MAML) 在 .NET 中进行扩展

转载 作者:IT王子 更新时间:2023-10-29 06:04:23 25 4
gpt4 key购买 nike

任何人都可以举出使用 Microsoft Azure 管理库 (MAML) 来扩展 Redis 缓存服务的示例吗?

我必须使用旧版本 Microsoft.Azure.Management.Redis.dll v0.9.0.0,因此 RedisManagementClient 不会接收 token ,而只会接收凭据。在这种情况下会出现异常

"AuthenticationFailed: Authentication failed. The 'Authorization' header is missing."

这是我正在使用的代码:

  public static void ScaleRedis(eSubscriptionType subscriptionType)
{

RedisManagementClient client = new RedisManagementClient(AzureCredentials.GetCredentials(subscriptionType));


var redisParams = new RedisCreateOrUpdateParameters()
{
Properties = new RedisProperties(version, new Sku(redisSKUName, redisSKUFamily, redisSKUCapacity), false),
Location = redisCacheRegion
};
client.Redis.CreateOrUpdate(resourceGroupName, cacheName, redisParams);


}

最佳答案

I must use older version Microsoft.Azure.Management.Redis.dll, v0.9.0.0, and so the RedisManagementClient do not receive token, but only credentials.

据我所知,名为 Microsoft.Azure.* 的库用于调用 ARM REST APITokenCloudCredentials ,而 Microsoft.WindowsAzure.* 可以与 CertificateCloudCredentials 一起使用.

如果您使用 MAML 和 CertificateCloudCredentials 来管理 Redis 缓存,您将收到以下错误消息:

AuthenticationFailed:身份验证失败。缺少“授权” header 。

杠杆Fiddler ,您可以找到详细的错误如下:

考虑到您正在使用 Microsoft.Azure.Management.Redis.dll (v0.9.0),用于管理 Redis 缓存的代码将如下所示:

TokenCloudCredentials tokenCredential = new TokenCloudCredentials("{your-subscriptionId}", "{token}");
RedisManagementClient client = new RedisManagementClient(tokenCredential);
var redisParams = new RedisCreateOrUpdateParameters()
{
Properties = new RedisProperties(version, new Sku(redisSKUName, redisSKUFamily, redisSKUCapacity)),
Location = redisCacheRegion
};
client.Redis.CreateOrUpdate(resourceGroupName, cacheName, redisParams);

注意:

更新

这是我的packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Azure.Management.Redis" version="0.9.0-preview" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.13.8" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common" version="1.3.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
</packages>

结果:

关于Azure Redis,如何使用 Microsoft Azure 管理库 (MAML) 在 .NET 中进行扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41923318/

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