我正在尝试在 asp.net MVC 应用程序中从 c# 创建一个存储,但它会抛出错误帐户类型 StandardLRS 无效,如下所示
下面是我用于创建的代码
string token = GetAccessToken("sub id", "app name", "tenant id");
var Credentials = new TokenCredentials(token);
var resourceManagementClient = new ResourceManagementClient(Credentials);
resourceManagementClient.SubscriptionId = "sub id";
var storageProvider = resourceManagementClient.Providers.Register("Microsoft.Storage");
var storageManagementClient = new StorageManagementClient(Credentials);
storageManagementClient.SubscriptionId = "sub id";
string rgName = "TimedCloudRG" + location.Trim().Replace(" ", string.Empty);
var resourceGroup = new Microsoft.Azure.Management.Resources.Models.ResourceGroup
{
Location = location
};
var rgResult = resourceManagementClient.ResourceGroups.CreateOrUpdate(rgName, resourceGroup);
Microsoft.Azure.Management.Storage.Models.Sku DefaultSku = new Microsoft.Azure.Management.Storage.Models.Sku(Microsoft.Azure.Management.Storage.Models.SkuName.StandardLRS);
Microsoft.Azure.Management.Storage.Models.Kind DefaultKind = Microsoft.Azure.Management.Storage.Models.Kind.Storage;
Microsoft.Azure.Management.Storage.Models.StorageAccountCreateParameters parameters = new Microsoft.Azure.Management.Storage.Models.StorageAccountCreateParameters()
{
Kind = DefaultKind,
Sku = DefaultSku,
Location = rgResult.Location
};
string stAccName = "TCStorageAccount"+Guid.NewGuid().ToString().Substring(0, 8);
var storageAccount = await storageManagementClient.StorageAccounts.CreateAsync(rgName, stAccName, parameters);
令人惊讶的是,当我在控制台应用程序上运行它时它运行良好。我也尝试安装 Microsoft.Azure.Management.Storage.Fluent 包,但无法安装,因为我的项目 .net 框架选择为 4.5.1,并且该版本不支持此包。
任何帮助将不胜感激。谢谢