2017-08-31 86 views
1

我想創建從C#在asp.net MVC應用程序中的存儲,但它拋出我的錯誤帳戶類型StandardLRS是無效的,因爲你可以看到下面無法在Azure C#創建存儲帳戶

Exception

下面是我使用創造

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,並且此軟件包不支持該版本。

任何幫助將不勝感激。由於

回答

1

根據你的描述,我利用Microsoft.Azure.Management.Storage 6.2.0-preview支持.NETFramework 4.5來檢查這個問題。我指定LocationWest US,我可以創建我的存儲帳戶。

string stAccName =「TCStorageAccount」+ Guid.NewGuid()。ToString()。Substring(0,8);

AFAIK,您的帳戶名稱不是有效的存儲帳戶名稱。存儲賬戶名稱必須和字符的長度和使用數字和小寫字母之間只有3 24

我試圖在Azure門戶創建存儲帳戶,並意外地發現了以下結果:

enter image description here

由於Locally redundant storage提到如下:

一些應用僅限於中複製數據由於數據治理要求而成爲一個國家。配對區域可能在另一個國家。有關區域對的更多信息,請參閱Azure regions

此外,您可以使用支持.NETFramework 4.5Microsoft.Azure.Management.Storage.Fluent 1.0.0

UPDATE:

我創建了一個示例AspDotNet-MVC-CreateAzureStorageAccount和定義的CreateAzureStorageAccount行動HomeController.cs下創建存儲帳戶。下面是測試結果,你可以把它稱爲如下:

enter image description here

+0

非常感謝您的回覆。我從版本5.2.0預覽升級DLL Microsoft.Azure.Management.Storage到6.5.0預覽和我也有我的升級代碼,並根據你的建議,我已經鑄成以小寫存儲帳戶名,但現在我有仍然是相同的例外。我曾嘗試使用相同的位置,但它仍然給我同樣的錯誤,即帳戶類型無效。即使我試圖與所有帳戶類型,如standardGRS等,但仍然是相同的異常。 –

+0

您創建存儲帳戶的位置是什麼?您是否嘗試在Azure Portal上創建存儲帳戶以縮小此問題的範圍? –

+0

我可以在門戶網站上使用standardLRS在門戶網站上創建存儲帳戶,而不會出現任何問題,但無法使用c#代碼在美國西部,澳大利亞東部創建存儲帳戶。 –