我想創建從C#在asp.net MVC應用程序中的存儲,但它拋出我的錯誤帳戶類型StandardLRS是無效的,因爲你可以看到下面無法在Azure C#創建存儲帳戶
下面是我使用創造
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,並且此軟件包不支持該版本。
任何幫助將不勝感激。由於
非常感謝您的回覆。我從版本5.2.0預覽升級DLL Microsoft.Azure.Management.Storage到6.5.0預覽和我也有我的升級代碼,並根據你的建議,我已經鑄成以小寫存儲帳戶名,但現在我有仍然是相同的例外。我曾嘗試使用相同的位置,但它仍然給我同樣的錯誤,即帳戶類型無效。即使我試圖與所有帳戶類型,如standardGRS等,但仍然是相同的異常。 –
您創建存儲帳戶的位置是什麼?您是否嘗試在Azure Portal上創建存儲帳戶以縮小此問題的範圍? –
我可以在門戶網站上使用standardLRS在門戶網站上創建存儲帳戶,而不會出現任何問題,但無法使用c#代碼在美國西部,澳大利亞東部創建存儲帳戶。 –