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

标签 azure redis azure-sdk-.net azure-redis-cache

任何人都可以举出使用 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/

相关文章:

c# - 在 Azure Web 和辅助角色中共享 SQL Server CE 数据库

redis - Redis 和 Kafka 的区别

ruby-on-rails - 在 Ruby on Rails 中使用 Redis 的 "Keys *"

c# - 如何从 Azure 门户获取事件日志

azure - Windows Azure SDK v1.6 不包含 csrun.exe,在哪里可以下载?

c# - Azure函数访问存储帐户

azure - 如何在azure搜索中为lucene添加自定义停用词?

azure - Windows Azure Active Directory 和 Office 365 集成

redis - 使用 Jredisearch 创建索引时添加前缀

c# - Azure 表存储 SDK - 清空表