无法在Azure C#上创建存储帐户 [英] Unable to create Storage account on Azure C#

查看:105
本文介绍了无法在Azure C#上创建存储帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从asp.net MVC应用程序中的c#创建存储,但它引发了我错误帐户类型StandardLRS无效,如下所示

下面是我用于创建的代码

 字符串令牌= GetAccessToken("sub id","app name","tenant id");var Credentials = new TokenCredentials(token);var resourceManagementClient =新的ResourceManagementClient(Credentials);resourceManagementClient.SubscriptionId =子ID";var storageProvider = resourceManagementClient.Providers.Register("Microsoft.Storage");var storageManagementClient =新的StorageManagementClient(Credentials);storageManagementClient.SubscriptionId =子ID";字符串rgName ="TimedCloudRG" + location.Trim().Replace(",string.Empty);var resourceGroup =新的Microsoft.Azure.Management.Resources.Models.ResourceGroup{位置=位置};var rgResult = resourceManagementClient.ResourceGroups.CreateOrUpdate(rgName,resourceGroup);Microsoft.Azure.Management.Storage.Models.Sku DefaultSku =新的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参数=新的Microsoft.Azure.Management.Storage.Models.StorageAccountCreateParameters(){种类= DefaultKind,Sku = DefaultSku,位置= rgResult.Location};字符串stAccName ="TCStorageAccount" + Guid.NewGuid().ToString().Substring(0,8);var storageAccount =等待storageManagementClient.StorageAccounts.CreateAsync(rgName,stAccName,parameters); 

令人惊讶的是,当我在控制台应用程序上运行它时,它可以正常工作.我还尝试安装Microsoft.Azure.Management.Storage.Fluent程序包,但无法将我的项目.net框架安装为4.5.1,并且该版本不支持该程序包.

任何帮助将不胜感激.谢谢

解决方案

根据您的描述,我利用了

I am trying to create a storage from c# in asp.net MVC application but it throws me error Account type StandardLRS is invalid as you can see below

Below is the code which I am using for creation

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);

Surprisingly it works fine when I run it on console application. I also try to install Microsoft.Azure.Management.Storage.Fluent package but unable to install as my project .net framework selected as 4.5.1 and this package not supported to that version.

Any help would be greatly appreciated. Thanks

解决方案

According to your description, I leveraged Microsoft.Azure.Management.Storage 6.2.0-preview which supports .NETFramework 4.5 to check this issue. I specified the Location as West US and I could create my storage account.

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

AFAIK, your account name is not a valid storage account name. Storage account name must be between 3 and 24 characters in length and use numbers and lower-case letters only.

I tried to create storage account on Azure Portal and accidentally found the following result:

As Locally redundant storage mentioned as follows:

Some applications are restricted to replicating data only within a country due to data governance requirements. A paired region could be in another country. For more information on region pairs, see Azure regions.

Additionally, you could use Microsoft.Azure.Management.Storage.Fluent 1.0.0 which supports .NETFramework 4.5.

UPDATE:

I created a sample AspDotNet-MVC-CreateAzureStorageAccount and defined the CreateAzureStorageAccount action for creating storage account under HomeController.cs. Here is the test result, you could refer to it as follows:

这篇关于无法在Azure C#上创建存储帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆